[][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());

Methods

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.

Auto Trait Implementations

impl Send for InputChain

impl Sync for InputChain

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

The type returned in the event of a conversion error.

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

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