mail_headers_ng/convert.rs
1//TODO potentially move HeaderTryFrom to `mail-headers`
2use error::ComponentCreationError;
3
4//TODO replace with std TryFrom once it is stable
5// (either a hard replace, or a soft replace which implements HeaderTryFrom if TryFrom exist)
6/// Workaround for `TryFrom`,`TryInto` not being stable.
7pub trait HeaderTryFrom<T>: Sized {
8 fn try_from(val: T) -> Result<Self, ComponentCreationError>;
9}
10
11/// Workaround for `TryFrom`,`TryInto` not being stable.
12pub trait HeaderTryInto<T>: Sized {
13 fn try_into(self) -> Result<T, ComponentCreationError>;
14}
15
16impl<F, T> HeaderTryInto<T> for F where T: HeaderTryFrom<F> {
17 fn try_into(self) -> Result<T, ComponentCreationError> {
18 T::try_from(self)
19 }
20}
21
22
23impl<T> HeaderTryFrom<T> for T {
24 fn try_from(val: T) -> Result<Self, ComponentCreationError> {
25 Ok( val )
26 }
27}
28
29// It is not possible to auto-implement HeaderTryFrom for From/Into as
30// this will make new HeaderTryFrom implementations outside of this care
31// nearly impossible making the trait partially useless
32//
33//impl<T, F> HeaderTryFrom<F> for T where F: Into<T> {
34// fn try_from(val: F) -> Result<T, Error> {
35// Ok( val.into() )
36// }
37//}