Trait mail_headers::HeaderKind
source · pub trait HeaderKind: Clone + Default + 'static {
type Component: EncodableInHeader + Clone;
const VALIDATOR: Option<HeaderMapValidator>;
const MAX_ONE: bool;
fn name() -> HeaderName;
fn auto_body<H>(body: H) -> Result<Header<Self>, ComponentCreationError>
where
H: HeaderTryInto<Self::Component>,
{ ... }
fn body(body: Self::Component) -> Header<Self> { ... }
}Expand description
Trait representing a mail header.
This is not meant to be implemented by hand.*
Use the def_headers macro instead.
Required Associated Types
sourcetype Component: EncodableInHeader + Clone
type Component: EncodableInHeader + Clone
the component representing the header-field, e.g. Unstructured for Subject
Required Associated Constants
sourceconst VALIDATOR: Option<HeaderMapValidator>
const VALIDATOR: Option<HeaderMapValidator>
A function which is meant to be called with a reference
to the final header map before encoding the headers. It is
meant to be used do some of the contextual validations,
like e.g. a From header might return a function which
checks if the From header has multiple mailboxes and
if so checks if there is a Sender header
Calling a contextual validator with a header map not containing a header which it is meant to validate should not cause an error. Only if the header is there and the component is of the expected type and it is invalid in the context an error should be returned.
sourceconst MAX_ONE: bool
const MAX_ONE: bool
I true this will assure that the header is at most one time in a header map.
This is similar to VALIDATOR (and can be archived through one) but in difference
to any VALIDATOR this is already assured when inserting a header with MAX_ONE set
to true in a header map. It exists so that the header map can do, what is most
intuitive, replacing insertion for all MAX_ONE headers (like in a normal map) but
use adding insertion for all other header (like in a multi map).
Most headers have this set to true.
Required Methods
sourcefn name() -> HeaderName
fn name() -> HeaderName
a method returning the header name
Note:
Once const fn is stable this will be changed to
a associated constant.
Provided Methods
sourcefn auto_body<H>(body: H) -> Result<Header<Self>, ComponentCreationError>where
H: HeaderTryInto<Self::Component>,
fn auto_body<H>(body: H) -> Result<Header<Self>, ComponentCreationError>where
H: HeaderTryInto<Self::Component>,
Creates a Header instance automatically converting given body to the right type.
Error
The type system assure that you can only use it on conversions
which are possible on type level, but they can still fail depending
on the actual data. For example creating a Email from a string
can fail if the string is not a valid email address. This in
turn means that creating a From header from a array of strings
can fail if one of them is not a valid email address.