[][src]Struct unsegen::input::InputChain

pub struct InputChain { /* fields omitted */ }

An intermediate element in a chain of Behaviors that are matched against the event and executed if applicable.

Examples:

use unsegen::input::*;

let mut triggered_first = false;
let mut triggered_second = false;
let mut triggered_third = false;

let input = Input {
    event: Event::Key(Key::Char('g')),
    raw: Vec::new(), //Incorrect, but does not matter for this example.
};

let res = input
    .chain((Key::Char('f'), || triggered_first = true)) // does not match, passes event on
    .chain(|i: Input| if let Event::Key(Key::Char(_)) = i.event {
        triggered_second = true;
        None // matches! event will be consumed
    } else {
        Some(i)
    })
    .chain((Key::Char('g'), || triggered_first = true)) // matches, but is not reached!
    .finish();

assert!(!triggered_first);
assert!(triggered_second);
assert!(!triggered_third);
assert!(res.is_none());

Implementations

impl InputChain[src]

pub fn chain<B: Behavior>(self, behavior: B) -> InputChain[src]

Add another behavior to the line of input processors that will try to consume the event one after another.

pub fn finish(self) -> Option<Input>[src]

Unpack the final chain value. If the Input was consumed by some Behavior, the result will be None, otherwise the original Input will be returned.

Trait Implementations

impl From<Input> for InputChain[src]

impl From<Option<Input>> for InputChain[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.

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.