Struct unsegen::input::InputChain [−][src]
pub struct InputChain { /* fields omitted */ }
Expand description
An intermediate element in a chain of Behavior
s 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]
impl InputChain
[src]pub fn chain<B: Behavior>(self, behavior: B) -> 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 chain_and_then<B: Behavior>(
self,
behavior: B,
f: impl FnOnce()
) -> InputChain
[src]
pub fn chain_and_then<B: Behavior>(
self,
behavior: B,
f: impl FnOnce()
) -> InputChain
[src]Add another behavior to the line of input processors that will try to consume the event one after another.
If this chain element consumes the input, f
is executed.
pub fn finish(self) -> Option<Input>
[src]
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.
pub fn if_consumed(self, f: impl FnOnce()) -> Self
[src]
pub fn if_consumed(self, f: impl FnOnce()) -> Self
[src]Execute the provided function only if the input was consumed previously in the chain.
pub fn if_not_consumed(self, f: impl FnOnce()) -> Self
[src]
pub fn if_not_consumed(self, f: impl FnOnce()) -> Self
[src]Execute the provided function only if the input not was consumed previously in the chain.