let query: Option<&HashMap<String, Vec<String>>> = req.get_ref::<UrlEncodedQuery>().ok();
let code_vector: Option<&Vec<String>> = if let Some(query) = query {
query.get("code")
} else {
None
};
let code: Option<&String> = if let Some(code_vector) = code_vector {
Some(&code_vector[0])
} else {
None
};
Code doesn't work
let code: Option<&String> = req.get_ref::<UrlEncodedQuery>()
.ok()
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
.map(|codes| &codes[0]);
Errors
error: cannot infer an appropriate lifetime for autoref due to conflicting requirements [E0495]
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
^~~~~~~~~~~
note: first, the lifetime cannot outlive the expression
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
^~~~~
note: ...so that auto-reference is valid at the time of borrow
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
^~~~~
note: but, the lifetime must be valid for the method call at 78:75...
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
^~~~~~~~~~~~~~~~~
note: ...so that method receiver is valid for the method call
.and_then(|query: &HashMap<String, Vec<String>>| query.get("code"))
^~~~~