diff options
Diffstat (limited to 'headers/src')
34 files changed, 1255 insertions, 1379 deletions
diff --git a/headers/src/convert.rs b/headers/src/convert.rs index 1153965..c076cfd 100644 --- a/headers/src/convert.rs +++ b/headers/src/convert.rs @@ -13,16 +13,18 @@ pub trait HeaderTryInto<T>: Sized { fn try_into(self) -> Result<T, ComponentCreationError>; } -impl<F, T> HeaderTryInto<T> for F where T: HeaderTryFrom<F> { +impl<F, T> HeaderTryInto<T> for F +where + T: HeaderTryFrom<F>, +{ fn try_into(self) -> Result<T, ComponentCreationError> { T::try_from(self) } } - impl<T> HeaderTryFrom<T> for T { fn try_from(val: T) -> Result<Self, ComponentCreationError> { - Ok( val ) + Ok(val) } } @@ -34,4 +36,4 @@ impl<T> HeaderTryFrom<T> for T { // fn try_from(val: F) -> Result<T, Error> { // Ok( val.into() ) // } -//}
\ No newline at end of file +//} diff --git a/headers/src/data/inner_item.rs b/headers/src/data/inner_item.rs index 147a959..9113e15 100644 --- a/headers/src/data/inner_item.rs +++ b/headers/src/data/inner_item.rs @@ -1,13 +1,12 @@ +use std::borrow::ToOwned; use std::ops::Deref; use std::sync::Arc; -use std::borrow::ToOwned; use owning_ref::OwningRef; -use soft_ascii_string::{SoftAsciiString, SoftAsciiStr}; - -#[cfg(feature="serde")] -use serde::{Serialize, Deserialize, Serializer, Deserializer, de::Error as __Error}; +use soft_ascii_string::{SoftAsciiStr, SoftAsciiString}; +#[cfg(feature = "serde")] +use serde::{de::Error as __Error, Deserialize, Deserializer, Serialize, Serializer}; /// InnerAscii is string data container which can contain either a /// owned `SoftAsciiString` or a `SoftAsciiStr` reference into a shared @@ -16,11 +15,10 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer, de::Error as __Err pub enum InnerAscii { Owned(SoftAsciiString), //by using String+SoftAsciiStr we can eliminate unessesary copies - Shared(OwningRef<Arc<String>, SoftAsciiStr>) + Shared(OwningRef<Arc<String>, SoftAsciiStr>), } impl InnerAscii { - /// converts this container into on which uses underlying shared data /// /// if the data is already shared nothing is done. @@ -43,7 +41,7 @@ impl InnerAscii { }); InnerAscii::Shared(orf) } - v => v + v => v, } } } @@ -55,11 +53,10 @@ impl InnerAscii { pub enum InnerUtf8 { Owned(String), //by using String+SoftAsciiStr we can eliminate unessesary copies - Shared(OwningRef<Arc<String>, str>) + Shared(OwningRef<Arc<String>, str>), } impl InnerUtf8 { - /// converts this container into on which uses underlying shared data /// /// if the data is already shared nothing is done. @@ -69,34 +66,32 @@ impl InnerUtf8 { match self { InnerUtf8::Owned(value) => { let buffer = Arc::new(value); - let orf = OwningRef::new(buffer) - .map(|rced| &**rced); + let orf = OwningRef::new(buffer).map(|rced| &**rced); InnerUtf8::Shared(orf) } - v => v + v => v, } } } - macro_rules! inner_impl { - ($name:ident, $owned_form:ty, $borrowed_form:ty) => ( + ($name:ident, $owned_form:ty, $borrowed_form:ty) => { impl $name { - pub fn new<S: Into<$owned_form>>( data: S ) -> Self { - $name::Owned( data.into() ) + pub fn new<S: Into<$owned_form>>(data: S) -> Self { + $name::Owned(data.into()) } } impl From<$owned_form> for $name { - fn from( data: $owned_form ) -> Self { - Self::new( data ) + fn from(data: $owned_form) -> Self { + Self::new(data) } } impl Into<$owned_form> for $name { fn into(self) -> $owned_form { match self { - $name::Owned( owned ) => owned, - $name::Shared( shared ) => { + $name::Owned(owned) => owned, + $name::Shared(shared) => { let as_ref: &$borrowed_form = &*shared; as_ref.to_owned() } @@ -107,22 +102,23 @@ macro_rules! inner_impl { impl Deref for $name { type Target = $borrowed_form; - fn deref( &self ) -> &$borrowed_form{ + fn deref(&self) -> &$borrowed_form { match *self { - $name::Owned( ref string ) => &*string, - $name::Shared( ref owning_ref ) => &*owning_ref + $name::Owned(ref string) => &*string, + $name::Shared(ref owning_ref) => &*owning_ref, } } } - #[cfg(feature="serde")] + #[cfg(feature = "serde")] impl Serialize for $name { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> - where S: Serializer + where + S: Serializer, { let borrowed: &$borrowed_form = &*self; let as_ref: &str = borrowed.as_ref(); - serializer.serialize_str( as_ref ) + serializer.serialize_str(as_ref) } } @@ -139,100 +135,89 @@ macro_rules! inner_impl { self.as_str() } } - ); + }; } -inner_impl!{ InnerAscii, SoftAsciiString, SoftAsciiStr } -inner_impl!{ InnerUtf8, String, str } +inner_impl! { InnerAscii, SoftAsciiString, SoftAsciiStr } +inner_impl! { InnerUtf8, String, str } //inner_impl!{ InnerOtherItem, OtherString, OtherStr } impl InnerAscii { - pub fn as_str( &self ) -> &str { + pub fn as_str(&self) -> &str { match *self { - InnerAscii::Owned( ref owned ) => owned.as_str(), - InnerAscii::Shared( ref shared ) => shared.as_str() + InnerAscii::Owned(ref owned) => owned.as_str(), + InnerAscii::Shared(ref shared) => shared.as_str(), } } } -#[cfg(feature="serde")] +#[cfg(feature = "serde")] impl<'de> Deserialize<'de> for InnerAscii { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where D: Deserializer<'de> + where + D: Deserializer<'de>, { - let content = String::deserialize(deserializer) - .map_err(|err| D::Error::custom(err))?; - let content = SoftAsciiString::from_string(content) - .map_err(|err| D::Error::custom(err))?; + let content = String::deserialize(deserializer).map_err(|err| D::Error::custom(err))?; + let content = SoftAsciiString::from_string(content).map_err(|err| D::Error::custom(err))?; Ok(InnerAscii::from(content)) } } impl InnerUtf8 { - pub fn as_str( &self ) -> &str { + pub fn as_str(&self) -> &str { match *self { - InnerUtf8::Owned( ref owned ) => owned.as_str(), - InnerUtf8::Shared( ref shared ) => &**shared + InnerUtf8::Owned(ref owned) => owned.as_str(), + InnerUtf8::Shared(ref shared) => &**shared, } } } -#[cfg(feature="serde")] +#[cfg(feature = "serde")] impl<'de> Deserialize<'de> for InnerUtf8 { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where D: Deserializer<'de> + where + D: Deserializer<'de>, { - let content = String::deserialize(deserializer) - .map_err(|err| D::Error::custom(err))?; + let content = String::deserialize(deserializer).map_err(|err| D::Error::custom(err))?; Ok(InnerUtf8::from(content)) } } - #[cfg(test)] mod test { use super::*; #[test] fn inner_ascii_item_eq() { - let a = InnerAscii::Owned( SoftAsciiString::from_string( "same" ).unwrap() ); + let a = InnerAscii::Owned(SoftAsciiString::from_string("same").unwrap()); let b = InnerAscii::Shared( - OwningRef::new(Arc::new("same".to_owned())) - .map(|v| SoftAsciiStr::from_unchecked(&**v)) + OwningRef::new(Arc::new("same".to_owned())).map(|v| SoftAsciiStr::from_unchecked(&**v)), ); - assert_eq!( a, b ); + assert_eq!(a, b); } #[test] fn inner_ascii_item_neq() { - let a = InnerAscii::Owned( SoftAsciiString::from_string( "same" ).unwrap() ); + let a = InnerAscii::Owned(SoftAsciiString::from_string("same").unwrap()); let b = InnerAscii::Shared( OwningRef::new(Arc::new("not same".to_owned())) - .map(|v| SoftAsciiStr::from_unchecked(&**v)) + .map(|v| SoftAsciiStr::from_unchecked(&**v)), ); - assert_ne!( a, b ); + assert_ne!(a, b); } #[test] fn inner_utf8_item_eq() { - let a = InnerUtf8::Owned( String::from( "same" ) ); - let b = InnerUtf8::Shared( - OwningRef::new( - Arc::new( String::from( "same" ) ) ) - .map(|v| &**v) - ); - assert_eq!( a, b ); + let a = InnerUtf8::Owned(String::from("same")); + let b = InnerUtf8::Shared(OwningRef::new(Arc::new(String::from("same"))).map(|v| &**v)); + assert_eq!(a, b); } #[test] fn inner_utf8_item_neq() { - let a = InnerUtf8::Owned( String::from( "same" ) ); - let b = InnerUtf8::Shared( - OwningRef::new( - Arc::new( String::from( "not same" ) ) ) - .map(|v| &**v) - ); - assert_ne!( a, b ); + let a = InnerUtf8::Owned(String::from("same")); + let b = InnerUtf8::Shared(OwningRef::new(Arc::new(String::from("not same"))).map(|v| &**v)); + assert_ne!(a, b); } #[test] @@ -241,11 +226,8 @@ mod test { assert_eq!( "hy", - InnerAscii::Owned( SoftAsciiStr::from_unchecked("hy").to_owned() ).as_str() - ); - assert_eq!( - "hy", - InnerUtf8::Owned( "hy".into() ).as_str() + InnerAscii::Owned(SoftAsciiStr::from_unchecked("hy").to_owned()).as_str() ); + assert_eq!("hy", InnerUtf8::Owned("hy".into()).as_str()); } -}
\ No newline at end of file +} diff --git a/headers/src/data/input.rs b/headers/src/data/input.rs index ad43d10..c3cbdeb 100644 --- a/headers/src/data/input.rs +++ b/headers/src/data/input.rs @@ -1,37 +1,32 @@ -use std::result::{ Result as StdResult }; use std::fmt::{self, Display}; +use std::result::Result as StdResult; use soft_ascii_string::SoftAsciiString; -use ::HeaderTryFrom; -use ::error::ComponentCreationError; +use error::ComponentCreationError; +use HeaderTryFrom; -use super::inner_item::{ InnerUtf8, InnerAscii }; +use super::inner_item::{InnerAscii, InnerUtf8}; /// a Input is similar to Item a container data container used in different /// context's with different restrictions, but different to an Item it /// might contain characters which require encoding (e.g. encoded words) /// to represent them #[derive(Debug, Clone, Hash, Eq, PartialEq)] -pub struct Input( pub InnerUtf8 ); - +pub struct Input(pub InnerUtf8); impl Input { - - pub fn into_shared( self ) -> Self { - Input( self.0.into_shared() ) + pub fn into_shared(self) -> Self { + Input(self.0.into_shared()) } - - pub fn into_ascii_item( self ) -> StdResult<InnerAscii, Input> { + pub fn into_ascii_item(self) -> StdResult<InnerAscii, Input> { match self { - Input( InnerUtf8::Owned( string ) ) => { - match SoftAsciiString::from_string(string) { - Ok(asciied) => Ok(InnerAscii::Owned(asciied)), - Err(err) => Err(Input(InnerUtf8::Owned(err.into_source()))) - } - } - Input( InnerUtf8::Shared( shared ) ) => { + Input(InnerUtf8::Owned(string)) => match SoftAsciiString::from_string(string) { + Ok(asciied) => Ok(InnerAscii::Owned(asciied)), + Err(err) => Err(Input(InnerUtf8::Owned(err.into_source()))), + }, + Input(InnerUtf8::Shared(shared)) => { if shared.is_ascii() { Ok(InnerAscii::Owned(SoftAsciiString::from_unchecked(&*shared))) } else { @@ -41,41 +36,40 @@ impl Input { } } - pub fn into_ascii_item_unchecked( self ) -> InnerAscii { + pub fn into_ascii_item_unchecked(self) -> InnerAscii { match self { - Input( InnerUtf8::Owned( string ) ) => - InnerAscii::Owned( SoftAsciiString::from_unchecked( string ) ), - Input( InnerUtf8::Shared( shared ) ) => - InnerAscii::Owned( - SoftAsciiString::from_unchecked(&*shared) ) + Input(InnerUtf8::Owned(string)) => { + InnerAscii::Owned(SoftAsciiString::from_unchecked(string)) + } + Input(InnerUtf8::Shared(shared)) => { + InnerAscii::Owned(SoftAsciiString::from_unchecked(&*shared)) + } } } - pub fn into_utf8_item( self ) -> InnerUtf8 { + pub fn into_utf8_item(self) -> InnerUtf8 { self.0 } } impl<'a> From<&'a str> for Input { - fn from( s: &'a str ) -> Self { - Input( InnerUtf8::Owned( s.into() ) ) + fn from(s: &'a str) -> Self { + Input(InnerUtf8::Owned(s.into())) } } impl From<String> for Input { - fn from( s: String ) -> Self { - Input( InnerUtf8::Owned( s ) ) + fn from(s: String) -> Self { + Input(InnerUtf8::Owned(s)) } } -impl<'a> HeaderTryFrom<&'a str> for Input -{ +impl<'a> HeaderTryFrom<&'a str> for Input { fn try_from(val: &'a str) -> Result<Self, ComponentCreationError> { Ok(val.into()) } } -impl HeaderTryFrom<String> for Input -{ +impl HeaderTryFrom<String> for Input { fn try_from(val: String) -> Result<Self, ComponentCreationError> { Ok(val.into()) } @@ -95,37 +89,28 @@ impl Display for Input { deref0!( +mut Input => InnerUtf8 ); - - #[cfg(test)] mod test { - use std::sync::Arc; use owning_ref::OwningRef; + use std::sync::Arc; use super::*; #[test] fn input_eq() { - let a = Input( InnerUtf8::Owned( "same".into() ) ); - let b = Input( InnerUtf8::Shared( - OwningRef::new( - Arc::new( String::from( "same" ) ) ) - .map(|v| &**v) - ) ); - assert_eq!( a, b ); + let a = Input(InnerUtf8::Owned("same".into())); + let b = Input(InnerUtf8::Shared( + OwningRef::new(Arc::new(String::from("same"))).map(|v| &**v), + )); + assert_eq!(a, b); } #[test] fn input_neq() { - let a = Input( InnerUtf8::Owned( "not same".into() ) ); - let b = Input( InnerUtf8::Shared( - OwningRef::new( - Arc::new( String::from( "not at all same" ) ) ) - .map(|v| &**v) - ) ); - assert_ne!( a, b ); + let a = Input(InnerUtf8::Owned("not same".into())); + let b = Input(InnerUtf8::Shared( + OwningRef::new(Arc::new(String::from("not at all same"))).map(|v| &**v), + )); + assert_ne!(a, b); } - - - -}
\ No newline at end of file +} diff --git a/headers/src/data/mod.rs b/headers/src/data/mod.rs index 4d22f1b..bd8b26e 100644 --- a/headers/src/data/mod.rs +++ b/headers/src/data/mod.rs @@ -20,4 +20,4 @@ mod input; pub use self::input::*; mod simple_item; -pub use self::simple_item::*;
\ No newline at end of file +pub use self::simple_item::*; diff --git a/headers/src/data/simple_item.rs b/headers/src/data/simple_item.rs index e0cd09f..68e21e4 100644 --- a/headers/src/data/simple_item.rs +++ b/headers/src/data/simple_item.rs @@ -1,106 +1,102 @@ use std::ops::Deref; -use soft_ascii_string::{ SoftAsciiStr, SoftAsciiString}; +use soft_ascii_string::{SoftAsciiStr, SoftAsciiString}; +use super::inner_item::{InnerAscii, InnerUtf8}; use super::input::Input; -use super::inner_item::{ InnerAscii, InnerUtf8 }; -#[cfg(feature="serde")] -use serde::{Serialize, Deserialize}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Hash, Eq, PartialEq)] -#[cfg_attr(feature="serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum SimpleItem { /// specifies that the Item is valid Ascii, nothing more - Ascii( InnerAscii ), + Ascii(InnerAscii), /// specifies that the Item is valid Utf8, nothing more - Utf8( InnerUtf8 ) + Utf8(InnerUtf8), } impl SimpleItem { - - pub fn as_str( &self ) -> &str { + pub fn as_str(&self) -> &str { use self::SimpleItem::*; match *self { - Ascii( ref value ) => value.as_str(), - Utf8( ref value ) => value.as_str() + Ascii(ref value) => value.as_str(), + Utf8(ref value) => value.as_str(), } } - pub fn is_ascii( &self ) -> bool { + pub fn is_ascii(&self) -> bool { use self::SimpleItem::*; match *self { - Ascii( .. ) => true, - Utf8( .. ) => false + Ascii(..) => true, + Utf8(..) => false, } } - pub fn from_utf8_input( s: Input ) -> Self { - SimpleItem::Utf8( s.0 ) + pub fn from_utf8_input(s: Input) -> Self { + SimpleItem::Utf8(s.0) } - pub fn from_utf8( s: String ) -> Self { - SimpleItem::Utf8( InnerUtf8::Owned( s ) ) + pub fn from_utf8(s: String) -> Self { + SimpleItem::Utf8(InnerUtf8::Owned(s)) } - - } impl Deref for SimpleItem { type Target = str; - fn deref( &self ) -> &str { + fn deref(&self) -> &str { use self::SimpleItem::*; match *self { - Ascii( ref astr ) => astr.as_str(), - Utf8( ref utf8 ) => &**utf8 + Ascii(ref astr) => astr.as_str(), + Utf8(ref utf8) => &**utf8, } } } - impl Into<String> for SimpleItem { fn into(self) -> String { use self::SimpleItem::*; match self { - Ascii( aitem ) => { + Ascii(aitem) => { let astring: SoftAsciiString = aitem.into(); astring.into() - }, - Utf8( string ) => string.into() + } + Utf8(string) => string.into(), } } } impl<'a> From<&'a str> for SimpleItem { - fn from( string: &'a str ) -> Self { - Self::from( String::from( string ) ) + fn from(string: &'a str) -> Self { + Self::from(String::from(string)) } } impl From<String> for SimpleItem { - fn from( string: String ) -> Self { - match SoftAsciiString::from_string( string ) { - Ok( astring ) => SimpleItem::Ascii( InnerAscii::Owned( astring ) ), - Err( err ) => SimpleItem::Utf8( InnerUtf8::Owned( err.into_source() ) ) + fn from(string: String) -> Self { + match SoftAsciiString::from_string(string) { + Ok(astring) => SimpleItem::Ascii(InnerAscii::Owned(astring)), + Err(err) => SimpleItem::Utf8(InnerUtf8::Owned(err.into_source())), } } } impl From<SoftAsciiString> for SimpleItem { - fn from( astring: SoftAsciiString ) -> Self { - SimpleItem::Ascii( InnerAscii::Owned( astring ) ) + fn from(astring: SoftAsciiString) -> Self { + SimpleItem::Ascii(InnerAscii::Owned(astring)) } } impl From<Input> for SimpleItem { fn from(input: Input) -> Self { match input { - Input( InnerUtf8::Owned( string ) ) => match SoftAsciiString::from_string( string ) { - Ok( ascii ) => SimpleItem::Ascii( InnerAscii::Owned( ascii ) ), - Err( err ) => SimpleItem::Utf8( InnerUtf8::Owned( err.into_source() ) ) + Input(InnerUtf8::Owned(string)) => match SoftAsciiString::from_string(string) { + Ok(ascii) => SimpleItem::Ascii(InnerAscii::Owned(ascii)), + Err(err) => SimpleItem::Utf8(InnerUtf8::Owned(err.into_source())), }, - Input( InnerUtf8::Shared( shared ) ) => { + Input(InnerUtf8::Shared(shared)) => { if shared.is_ascii() { let a_shared = shared.map(|s| SoftAsciiStr::from_unchecked(s)); SimpleItem::Ascii(InnerAscii::Shared(a_shared)) diff --git a/headers/src/error.rs b/headers/src/error.rs index beb92cb..b5a4aa5 100644 --- a/headers/src/error.rs +++ b/headers/src/error.rs @@ -1,31 +1,34 @@ //! module contains the (new) errors emitted by this crate use std::fmt::{self, Display}; -use failure::{Fail, Context, Error as FError, Backtrace}; +use failure::{Backtrace, Context, Error as FError, Fail}; -use ::name::HeaderName; +use name::HeaderName; /// This error can occur if different implementations for the /// same header (e.g. `Subject`) where used in the same `HeaderMap`. #[derive(Debug, Fail)] -#[fail(display = "cast error caused by mixing different header implementations for {}", header_name)] +#[fail( + display = "cast error caused by mixing different header implementations for {}", + header_name +)] pub struct HeaderTypeError { header_name: HeaderName, - backtrace: Backtrace + backtrace: Backtrace, } impl HeaderTypeError { pub fn new(name: HeaderName) -> Self { HeaderTypeError { header_name: name, - backtrace: Backtrace::new() + backtrace: Backtrace::new(), } } pub fn new_with_backtrace(name: HeaderName, backtrace: Backtrace) -> Self { HeaderTypeError { header_name: name, - backtrace + backtrace, } } } @@ -40,7 +43,7 @@ pub enum HeaderValidationError { #[fail(display = "{}", _0)] BuildIn(Context<BuildInValidationError>), #[fail(display = "{}", _0)] - Custom(FError) + Custom(FError), } impl From<BuildInValidationError> for HeaderValidationError { @@ -59,16 +62,21 @@ impl From<Context<BuildInValidationError>> for HeaderValidationError { /// when running a header map validator. #[derive(Copy, Clone, Debug, Fail, PartialEq, Eq, Hash)] pub enum BuildInValidationError { - /// This error is returned by `use_contextual_validators` if there is a "max one" inconsistency. /// /// I.e. if multiple implementations of the same header are used in the same map but /// the implementations do not agree on wether or not the header can appear at most one /// time in a header section. - #[fail(display = "{} header field contained both \"multi\" and \"max one\" header impl", header_name)] + #[fail( + display = "{} header field contained both \"multi\" and \"max one\" header impl", + header_name + )] MaxOneInconsistency { header_name: &'static str }, - #[fail(display = "{} header field can appear at most one time in a header map", header_name)] + #[fail( + display = "{} header field can appear at most one time in a header map", + header_name + )] MoreThenOne { header_name: &'static str }, #[fail(display = "From field contained multiple addresses but no Sender field was set")] @@ -78,7 +86,7 @@ pub enum BuildInValidationError { ResentDateFieldMissing, #[fail(display = "Resent-From field in resent block without a Resent-Sender field")] - MultiMailboxResentFromWithoutResentSender + MultiMailboxResentFromWithoutResentSender, } macro_rules! header_validation_bail { @@ -88,7 +96,6 @@ macro_rules! header_validation_bail { }); } - /// Helper type which is either a `Backtrace` or an full `failure::Error`. /// /// This can be used to either just contain a backtrace into an custom @@ -97,22 +104,21 @@ macro_rules! header_validation_bail { #[derive(Debug)] pub enum ChainTail { Backtrace(Backtrace), - Error(FError) + Error(FError), } impl ChainTail { - fn backtrace(&self) -> &Backtrace { match *self { ChainTail::Backtrace(ref trace) => trace, - ChainTail::Error(ref error) => error.backtrace() + ChainTail::Error(ref error) => error.backtrace(), } } fn as_fail(&self) -> Option<&Fail> { match *self { ChainTail::Backtrace(_) => None, - ChainTail::Error(ref error) => Some(error.as_fail()) + ChainTail::Error(ref error) => Some(error.as_fail()), } } } @@ -126,21 +132,21 @@ impl ChainTail { pub struct ComponentCreationError { component: &'static str, backtrace: ChainTail, - str_context: Option<String> + str_context: Option<String>, } impl ComponentCreationError { - /// create a new `ComponentCreationError` based on a different error and the name of the component /// /// The name is normally the type name, for example `Email`, `Mailbox` etc. pub fn from_parent<P>(parent: P, component: &'static str) -> Self - where P: Into<FError> + where + P: Into<FError>, { ComponentCreationError { component, backtrace: ChainTail::Error(parent.into()), - str_context: None + str_context: None, } } @@ -151,7 +157,7 @@ impl ComponentCreationError { ComponentCreationError { component, backtrace: ChainTail::Backtrace(Backtrace::new()), - str_context: None + str_context: None, } } @@ -162,27 +168,30 @@ impl ComponentCreationError { /// The `str_context` is a snipped of text which can help a human to identify the /// invalid parts, e.g. for parsing a email it could be the invalid email address. pub fn new_with_str<I>(component: &'static str, str_context: I) -> Self - where I: Into<String> + where + I: Into<String>, { ComponentCreationError { component, backtrace: ChainTail::Backtrace(Backtrace::new()), - str_context: Some(str_context.into()) + str_context: Some(str_context.into()), } } pub fn str_context(&self) -> Option<&str> { - self.str_context.as_ref().map(|s|&**s) + self.str_context.as_ref().map(|s| &**s) } pub fn set_str_context<I>(&mut self, ctx: I) - where I: Into<String> + where + I: Into<String>, { self.str_context = Some(ctx.into()); } pub fn with_str_context<I>(mut self, ctx: I) -> Self - where I: Into<String> + where + I: Into<String>, { self.set_str_context(ctx); self diff --git a/headers/src/header.rs b/headers/src/header.rs index b032e53..13a0bf8 100644 --- a/headers/src/header.rs +++ b/ |