Struct Tokenizer

Source
pub struct Tokenizer<'a, T: State> { /* private fields */ }
Expand description

Implements a Parser of IRC Messages as described in IRCv3 and RFC 1459.

The tokenizer implements both phases of a parser: Lexical and syntactical analysis. This is required as it implements a Zero-allocation parser which is not allocating anything on the heap and returns the next element based on its state.

Transitions between states are implemented with methods Tokenizer::tags, Tokenizer::prefix, Tokenizer::command, Tokenizer::params and Tokenizer::trailing. Based on the state different parts of the message can be parsed. If some parts of the message are not needed they are skipped by calling the wanted state transition method.

Implementations§

Source§

impl<'a> Tokenizer<'a, Start>

Source

pub fn new(raw: &'a str) -> Result<Self, ParserError>

Source

pub fn parse_partial( self, cfg: PartialCfg<'a>, ) -> Result<Parsed<'a>, ParserError>

Source

pub fn tags(self) -> Tokenizer<'a, TagsState>

Source

pub fn prefix(self) -> Tokenizer<'a, PrefixState>

Source

pub fn command(self) -> Tokenizer<'a, CommandState>

Source

pub fn params(self) -> Tokenizer<'a, ParamsState>

Source

pub fn trailing(self) -> Tokenizer<'a, TrailingState>

Source§

impl<'a> Tokenizer<'a, TagsState>

Source

pub fn as_iter(&mut self) -> IntoTagsIter<'a>

Source

pub fn prefix(self) -> Tokenizer<'a, PrefixState>

Source

pub fn command(self) -> Tokenizer<'a, CommandState>

Source

pub fn params(self) -> Tokenizer<'a, ParamsState>

Source

pub fn trailing(self) -> Tokenizer<'a, TrailingState>

Source§

impl<'a> Tokenizer<'a, PrefixState>

Source

pub fn name(&mut self) -> Result<Option<&'a str>, ParserError>

Source

pub fn user(&mut self) -> Result<Option<&'a str>, ParserError>

Source

pub fn host(&mut self) -> Result<Option<&'a str>, ParserError>

Source

pub fn parts(&mut self) -> Result<Option<Prefix<'a>>, ParserError>

Returns None if the prefix is badly formatted or no prefix is present.

Source

pub fn command(self) -> Tokenizer<'a, CommandState>

Source

pub fn params(self) -> Tokenizer<'a, ParamsState>

Source

pub fn trailing(self) -> Tokenizer<'a, TrailingState>

Source§

impl<'a> Tokenizer<'a, CommandState>

Source

pub fn command(&mut self) -> Result<&'a str, ParserError>

Source

pub fn params(self) -> Tokenizer<'a, ParamsState>

Source

pub fn trailing(self) -> Tokenizer<'a, TrailingState>

Source§

impl<'a> Tokenizer<'a, ParamsState>

Source

pub fn trailing(self) -> Tokenizer<'a, TrailingState>

Source

pub fn as_iter(&mut self) -> IntoParamsIter<'a>

Source§

impl<'a> Tokenizer<'a, TrailingState>

Source

pub fn trailing(&self) -> Option<&'a str>

Trait Implementations§

Source§

impl<'a, T: Clone + State> Clone for Tokenizer<'a, T>

Source§

fn clone(&self) -> Tokenizer<'a, T>

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<'a, T: Debug + State> Debug for Tokenizer<'a, T>

Source§

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

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

impl<'a> IntoIterator for Tokenizer<'a, ParamsState>

Source§

type Item = &'a str

The type of the elements being iterated over.
Source§

type IntoIter = IntoParamsIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for Tokenizer<'a, TagsState>

Source§

type Item = Result<(&'a str, &'a str), ParserError>

The type of the elements being iterated over.
Source§

type IntoIter = IntoTagsIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: PartialEq + State> PartialEq for Tokenizer<'a, T>

Source§

fn eq(&self, other: &Tokenizer<'a, T>) -> 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<'a, T: Copy + State> Copy for Tokenizer<'a, T>

Source§

impl<'a, T: Eq + State> Eq for Tokenizer<'a, T>

Source§

impl<'a, T: State> StructuralPartialEq for Tokenizer<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for Tokenizer<'a, T>

§

impl<'a, T> RefUnwindSafe for Tokenizer<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Tokenizer<'a, T>
where T: Send,

§

impl<'a, T> Sync for Tokenizer<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Tokenizer<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for Tokenizer<'a, T>
where T: UnwindSafe,

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.