diff --git a/src/header/name.rs b/src/header/name.rs index 9af18df..e7de075 100644 --- a/src/header/name.rs +++ b/src/header/name.rs @@ -1,7 +1,7 @@ use byte_str::ByteStr; use bytes::{Bytes, BytesMut}; -use std::{fmt, mem}; +use std::{convert, fmt, mem}; use std::borrow::Borrow; use std::hash::{Hash, Hasher}; use std::str::FromStr; @@ -32,6 +32,13 @@ pub struct HeaderName { inner: Repr, } +impl convert::Into for HeaderName { + #[inline] + fn into(self) -> Bytes { + self.inner.into() + } +} + /// Almost a full `HeaderName` #[derive(Debug, Hash)] pub struct HdrName<'a> { @@ -44,10 +51,28 @@ enum Repr { Custom(T), } +impl convert::Into for Repr +where T: convert::Into { + fn into(self) -> Bytes { + match self { + Repr::Standard(header) => + Bytes::from_static(header.as_str().as_bytes()), + Repr::Custom(header) => header.into() + } + } +} + // Used to hijack the Hash impl #[derive(Debug, Clone, Eq, PartialEq)] struct Custom(ByteStr); +impl convert::Into for Custom { + #[inline] + fn into(self) -> Bytes { + self.0.into() + } +} + #[derive(Debug, Clone)] struct MaybeLower<'a> { buf: &'a [u8], diff --git a/src/header/value.rs b/src/header/value.rs index 792c666..3007540 100644 --- a/src/header/value.rs +++ b/src/header/value.rs @@ -1,6 +1,6 @@ use bytes::Bytes; -use std::{char, cmp, fmt, str}; +use std::{char, cmp, convert, fmt, str}; use std::error::Error; use std::str::FromStr; @@ -19,6 +19,13 @@ pub struct HeaderValue { is_sensitive: bool, } +impl convert::Into for HeaderValue { + #[inline] + fn into(self) -> Bytes { + self.inner + } +} + /// A possible error when converting a `HeaderValue` from a string or byte /// slice. #[derive(Debug)]