Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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