1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

Export IntoHeaderValue

This commit is contained in:
Nikolay Kim
2019-04-03 12:44:47 -07:00
parent e738361e09
commit dfa0abf5a5
3 changed files with 24 additions and 38 deletions

View File

@ -2,6 +2,10 @@
## [0.1.0-alpha.4] - 2019-04-xx
### Changed
* Export IntoHeaderValue
### Deleted
* Removed PayloadBuffer

View File

@ -20,7 +20,6 @@ pub use self::common::*;
#[doc(hidden)]
pub use self::shared::*;
#[doc(hidden)]
/// A trait for any object that will represent a header field and value.
pub trait Header
where
@ -33,7 +32,6 @@ where
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError>;
}
#[doc(hidden)]
/// A trait for any object that can be Converted to a `HeaderValue`
pub trait IntoHeaderValue: Sized {
/// The type returned in the event of a conversion error.
@ -97,6 +95,26 @@ impl IntoHeaderValue for String {
}
}
impl IntoHeaderValue for usize {
type Error = InvalidHeaderValueBytes;
#[inline]
fn try_into(self) -> Result<HeaderValue, Self::Error> {
let s = format!("{}", self);
HeaderValue::from_shared(Bytes::from(s))
}
}
impl IntoHeaderValue for u64 {
type Error = InvalidHeaderValueBytes;
#[inline]
fn try_into(self) -> Result<HeaderValue, Self::Error> {
let s = format!("{}", self);
HeaderValue::from_shared(Bytes::from(s))
}
}
impl IntoHeaderValue for Mime {
type Error = InvalidHeaderValueBytes;