Skip to content

Instantly share code, notes, and snippets.

@FGRibreau
Last active September 29, 2023 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FGRibreau/918824a80aba1f675026551f6cd617a1 to your computer and use it in GitHub Desktop.
Save FGRibreau/918824a80aba1f675026551f6cd617a1 to your computer and use it in GitHub Desktop.
Convert a HeaderValue into a rust String
/// Additional conversion methods for `HeaderValue`.
pub trait HeaderValueExt {
fn to_string(&self) -> String;
}
impl HeaderValueExt for HeaderValue {
fn to_string(&self) -> String {
self.to_str().unwrap_or_default().to_string()
}
}
// Usage:
let ok: Option<String> = request.headers().get("ok").map(|x| x.to_string());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment