Struct peepmatic_automata::Builder[][src]

pub struct Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
{ /* fields omitted */ }
Expand description

A builder for a transducer automata.

Type Parameters

Generic over the following parameters:

  • TAlphabet – the alphabet of the input strings. If your input keys are Strings, this would be char. If your input keys are arbitrary byte strings, this would be u8.

  • TState – extra, custom data associated with each state. This isn’t used by the automata itself, but you can use it to annotate states with extra information for your own purposes.

  • TOutput – the output type. See the Output trait for the requirements that any output type must fulfill.

Insertions

Insertions must happen in lexicographic order. Failure to do this, or inserting duplicates, will trigger panics.

Example

use peepmatic_automata::Builder;

let mut builder = Builder::<u8, (), u64>::new();

// Insert "mon" -> 1
let mut insertion = builder.insert();
insertion
    .next(b'm', 1)
    .next(b'o', 0)
    .next(b'n', 0);
insertion.finish();

// Insert "sat" -> 6
let mut insertion = builder.insert();
insertion
    .next(b's', 6)
    .next(b'a', 0)
    .next(b't', 0);
insertion.finish();

// Insert "sun" -> 0
let mut insertion = builder.insert();
insertion
    .next(b's', 0)
    .next(b'u', 0)
    .next(b'n', 0);
insertion.finish();

let automata = builder.finish();

assert_eq!(automata.get(b"sun"), Some(0));
assert_eq!(automata.get(b"mon"), Some(1));
assert_eq!(automata.get(b"sat"), Some(6));

assert!(automata.get(b"tues").is_none());

Implementations

impl<TAlphabet, TState, TOutput> Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
[src]

pub fn new() -> Self[src]

Make a new builder to start constructing a new transducer automata.

pub fn insert(&mut self) -> InsertionBuilder<'_, TAlphabet, TState, TOutput>[src]

Start building a new key/value insertion.

Insertions are built up incrementally, and a full entry is created from a series of TAlphabet and TOutput pairs passed to InsertionBuilder::next.

Panics

Panics if finish was not called on the last InsertionBuilder returned from this method.

pub fn finish(&mut self) -> Automaton<TAlphabet, TState, TOutput>[src]

Finish building this transducer and return the constructed Automaton.

Panics

Panics if this builder is empty, and has never had anything inserted into it.

Panics if the last insertion’s InsertionBuilder did not call its finish method.

Trait Implementations

impl<TAlphabet: Clone, TState: Clone, TOutput: Clone> Clone for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
[src]

fn clone(&self) -> Builder<TAlphabet, TState, TOutput>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<TAlphabet: Debug, TState: Debug, TOutput: Debug> Debug for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<TAlphabet, TState, TOutput> RefUnwindSafe for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: RefUnwindSafe,
    TOutput: RefUnwindSafe,
    TState: RefUnwindSafe

impl<TAlphabet, TState, TOutput> Send for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Send,
    TOutput: Send,
    TState: Send

impl<TAlphabet, TState, TOutput> Sync for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Sync,
    TOutput: Sync,
    TState: Sync

impl<TAlphabet, TState, TOutput> Unpin for Builder<TAlphabet, TState, TOutput> where
    TOutput: Unpin,
    TState: Unpin

impl<TAlphabet, TState, TOutput> UnwindSafe for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: RefUnwindSafe,
    TOutput: RefUnwindSafe + UnwindSafe,
    TState: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.