Created
December 8, 2018 13:39
-
-
Save igalic/6261f3f0124d2115cf88c31f7916a706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| match req { | |
| Ok(mut res) => { | |
| if let Ok(text) = &res.text() { | |
| if let Ok(ap_sign) = serde_json::from_str::<ApSignature>(text) { | |
| if let Ok(mut json) = serde_json::from_str::<CustomPerson>(text) { | |
| json.custom_props = ap_sign; // without this workaround, publicKey is not correctly deserialized | |
| Some(json) | |
| } else { | |
| None | |
| } | |
| } else { | |
| None | |
| } | |
| } else { | |
| None | |
| } | |
| } | |
| Err(e) => { | |
| println!("User fetch error: {:?}", e); | |
| None | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and_thenis basically a match expression that calls the passed function with the value ofTifselfisOk(T)and bypassesselfif it isErr(E), so you don't avoid anything there.The
and_thenexample doesn't work very well here because the value extraction can't be done in a fully stream-like fashion. To work around that without creating new variables (which is useless in itself) you have to do all that ugly indenting stuff that makes the code more difficult to read. The only thing you gain with that approach is not callingok()multiple times, but again, I think the real solution is to change the return type of the function.BTW I don't think losing information about
Erris a good idea, unless you are micro-optimizing hard on memory usage and transfers for a very good reason.