Trait HeaderKind

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

    const VALIDATOR: Option<HeaderMapValidator>;
    const MAX_ONE: bool;

    // Required method
    fn name() -> HeaderName;

    // Provided methods
    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 Constants§

Source

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.

Source

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 Associated Types§

Source

type Component: EncodableInHeader + Clone

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

Required Methods§

Source

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§

Source

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.

Source

fn body(body: Self::Component) -> Header<Self>

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl HeaderKind for Bcc

Source§

impl HeaderKind for Cc

Source§

impl HeaderKind for Comments

Source§

impl HeaderKind for ContentDescription

Source§

impl HeaderKind for ContentDisposition

Source§

impl HeaderKind for ContentId

Source§

impl HeaderKind for ContentTransferEncoding

Source§

impl HeaderKind for ContentType

Source§

impl HeaderKind for Date

Source§

impl HeaderKind for InReplyTo

Source§

impl HeaderKind for Keywords

Source§

impl HeaderKind for MessageId

Source§

impl HeaderKind for Received

Source§

impl HeaderKind for References

Source§

impl HeaderKind for ReplyTo

Source§

impl HeaderKind for ResentBcc

Source§

impl HeaderKind for ResentCc

Source§

impl HeaderKind for ResentDate

Source§

impl HeaderKind for ResentFrom

Source§

impl HeaderKind for ResentMsgId

Source§

impl HeaderKind for ResentSender

Source§

impl HeaderKind for ResentTo

Source§

impl HeaderKind for ReturnPath

Source§

impl HeaderKind for Sender

Source§

impl HeaderKind for Subject

Source§

impl HeaderKind for _From

Source§

impl HeaderKind for _To