HomeDevCentral

Map result values instead to use a match block

Description

Map result values instead to use a match block

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()
}

Reviewers: dereckson

Reviewed By: dereckson

Differential Revision: https://devcentral.nasqueron.org/D1950

Details

Provenance
derecksonAuthored on Oct 21 2018, 16:38
derecksonPushed on Oct 21 2018, 21:51
Reviewer
dereckson
Differential Revision
D1950: Map result values instead to use a match block
Parents
rLF9a386cc100e1: Fix typo
Branches
Unknown
Tags
Unknown