Charset

Enum Charset 

Source
#[repr(u8)]
pub enum Charset { QTextWs = 8, CTextWs = 1, DTextWs = 2, AText = 4, RestrictedToken = 16, Token = 32, ObsNoWsCtl = 64, Rfc7230Token = 128, }
Expand description

An enum for the charsets represented through an internal lookup table.

Variants§

§

QTextWs = 8

qtext + ws, basically anything which can appear in a quoted string which is not a quoted-pair.

Note: this is equivalent to rfc7230 qdtext, excluding the obsolete part of the grammar. Note: the obsolete part of the grammar is excluded

rfc: 5322

§

CTextWs = 1

ctext + ws

Note: the obsolete part of the grammar is excluded.

rfc: 5322

§

DTextWs = 2

dtext + ws

rfc: 5322

§

AText = 4

atext

rfc: 5322

§

RestrictedToken = 16

Restricted-name-char subset of rfc2045 token with which IETF-tokens and IANA-tokens have to comply.

rfc: 6838 (related rfc2045)

§

Token = 32

token

Note> there are multiple mail related definitions of token, this one is the rfc2045 based one.

rfc: 2045

§

ObsNoWsCtl = 64

obs-NO-WS-CTL

rfc: 5322

combine with CText or QText to support the obsolete part of the grammar

§Example

use mail_chars::{Charset, CharMatchExt, rfc5322};

fn is_ctext_with_obs(ch: char) -> bool {
    let res = Charset::lookup(ch);
    res.is(rfc5322::CTextWs) || res.is(rfc5322::ObsNoWsCtl)
}

assert!("\x01 comment \x02".chars().all(is_ctext_with_obs));
§

Rfc7230Token = 128

token

rfc: 7230

Token as defined in rfc7230 (HTTP/1.1) not directly a mail grammar, but relevant for shared utilities like e.g. anything Media Type (i.e. MIME-Type/Content-Type) related.

Implementations§

Source§

impl Charset

Source

pub fn contains(&self, ch: char) -> bool

Returns true if the char is part of this set of chars.

Source

pub fn contains_or_non_ascii(&self, ch: char) -> bool

Returns true if the char is part of the set of chars or not an ascii char.

This is mainly meant to be used in combination with rfc6532 which extends all *text grammar parts/character sets to contain any non-us-ascii character.

Source

pub fn lookup(ch: char) -> LookupResult

Uses the internal lookup table to classify a char.

Trait Implementations§

Source§

impl Clone for Charset

Source§

fn clone(&self) -> Charset

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Charset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Charset

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Charset

Source§

fn cmp(&self, other: &Charset) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Charset

Source§

fn eq(&self, other: &Charset) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Charset

Source§

fn partial_cmp(&self, other: &Charset) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Charset

Source§

impl Eq for Charset

Source§

impl StructuralPartialEq for Charset

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.