Skip to main content

ParserOptions

Struct ParserOptions 

Source
pub struct ParserOptions { /* private fields */ }
Expand description

Caller-provided configuration for the parser.

§Custom filters

The built-in filter vocabulary (is:unread, has:attachment, etc.) is fixed at compile time. Anything else — is:owed-reply, has:reaction, is:my-app-flag — returns ParseError::UnknownFilter by default. Register the names you want to accept so they parse as FilterKind::Custom instead.

use mail_query::{parse_with, FilterKind, ParserOptions, QueryNode};

let mut options = ParserOptions::default();
options.register_custom_filter("owed-reply");

let ast = parse_with("is:owed-reply", &options).expect("parses");
assert_eq!(
    ast,
    QueryNode::Filter(FilterKind::Custom("owed-reply".into()))
);

Implementations§

Source§

impl ParserOptions

Source

pub fn new() -> Self

New empty options. Equivalent to Default::default.

Source

pub fn register_custom_filter(&mut self, name: impl Into<String>) -> &mut Self

Register a custom filter name. The crate canonicalises to lowercase + hyphenated form (Reply_Later becomes reply-later), so callers can pass any casing.

Source

pub fn register_custom_filters<I, S>(&mut self, names: I) -> &mut Self
where I: IntoIterator<Item = S>, S: Into<String>,

Register many custom filter names at once.

Trait Implementations§

Source§

impl Debug for ParserOptions

Source§

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

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

impl Default for ParserOptions

Source§

fn default() -> ParserOptions

Returns the “default value” for a type. Read more

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> 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, 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.