Module email_parser::fsm

source ·
Expand description

Email parsing is accomplished using a finite state machine. FSM is defined in this module. Finite automaton has several states and transitions. When iterator is completely consumed, if the state is a final state, then given string is valid email address.

— Transition diagram or transition table —

Structs

  • Machine is the core export of the module. It is an IntoIterator and consuming the iterator determines if given string literal is a valid email address or not.
  • Iterator for the DFA implemented by Machine. Each step through the iterator consumes an input symbol (from input iterator) and transitions the DFA through the corresponding state. The iterator is exhausted when the input iterator gets exhausted. If any invalid character or invalid email address syntax is encountered, then transition is to State::Error. For every input symbol, this state consumes the symbol and remains in State::Error. Thus, parse errors can be checked just by investigating the state of DFA when input gets exhausted.

Enums

  • The set of possible states in a DFA that represents a language accepting all valid email addresses. State::Error is a dead state (or trap state).

Traits

  • FSM is an abstraction over behavior of deterministic finite automata. A DFA has a set of states (generic type S) and alphabets (all possible symbols). One of them is a start state (start fn). A transition takes the DFA from one state to other by consuming a symbol. If the input is completely consumed and DFA is in a final state (or accepting state) then we say that the input belongs to the language accepted by the DFA.