Page MenuHomeDevCentral

Map result values instead to use a match block
ClosedPublic

Authored by dereckson on Oct 21 2018, 21:47.
Tags
None
Referenced Files
F2747884: D1950.id4932.diff
Fri, Mar 29, 07:20
F2744215: D1950.diff
Thu, Mar 28, 14:54
Unknown Object (File)
Wed, Mar 27, 22:20
Unknown Object (File)
Tue, Mar 26, 10:44
Unknown Object (File)
Fri, Mar 22, 22:58
Unknown Object (File)
Thu, Mar 21, 15:19
Unknown Object (File)
Wed, Mar 13, 07:43
Unknown Object (File)
Wed, Mar 6, 04:43
Subscribers
None

Details

Summary

To map a result, ie a success T or an error E, into another result,
ie a success U or an error F means the code focus on T -> U, without
regard it's an Ok, and E -> F, without regard it's an Err value.

As such, it's seems more natural to express the idea with
methods manipulating tbe values than to recreate the enum container too.

The Serde library uses those map and map_err methods.

Test Plan
#[get("/player/<name>")]
pub fn get_player(connection: DatabaseConnection, name: String) -> ApiJsonResponse<Player> {
    players
        .filter(username.eq(&name))
        .first::<Player>(&*connection)
        .into_json_response()
}

Diff Detail

Repository
rLF Limiting Factor
Lint
Lint Passed
Unit
No Test Coverage
Branch
map_map_err (branched from master)
Build Status
Buildable 3038
Build 3286: arc lint + arc unit

Event Timeline

dereckson created this revision.
This revision is now accepted and ready to land.Oct 21 2018, 21:50
This revision was automatically updated to reflect the committed changes.