Trait mail::HeaderKind

source ·
pub trait HeaderKind: 'static + Clone + Default {
    type Component: EncodableInHeader + Clone;

    const VALIDATOR: Option<fn(_: &HeaderMap) -> Result<(), HeaderValidationError>>;
    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

Re-export of headers from mail-headers. Trait representing a mail header.

This is not meant to be implemented by hand.* Use the def_headers macro instead.

Required Associated Types

the component representing the header-field, e.g. Unstructured for Subject

Required Associated Constants

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.

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

a method returning the header name

Note:

Once const fn is stable this will be changed to a associated constant.

Provided Methods

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.

Creates a Header instance for this header kind with given body.

Implementors