Skip to content

Instantly share code, notes, and snippets.

@andete
Created June 17, 2017 07:58
Show Gist options
  • Save andete/b5ce0851041546449f3d577b520cb4f9 to your computer and use it in GitHub Desktop.
Save andete/b5ce0851041546449f3d577b520cb4f9 to your computer and use it in GitHub Desktop.
impl<'a, 'r> FromRequest<'a, 'r> for Lang {
type Error = ();
fn from_request(request: &'a Request<'r>) -> Outcome<Lang, ()> {
match request.cookies().get_private("lang") {
Some(r) => {
match Lang::from_str(r.value()) {
Ok(l) => Success(l),
Err(_) => Success(Lang::default()),
}
}
None => Success(Lang::default()),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment