Trait rsynth::event::EventHandlerExt[][src]

pub trait EventHandlerExt<E> {
    fn map<EE, F>(&mut self, function: F) -> Map<'_, Self, F>
    where
        F: FnMut(EE) -> E
, { ... } }

An extension trait for EventHandler providing some convenient combinator functions.

Provided methods

fn map<EE, F>(&mut self, function: F) -> Map<'_, Self, F> where
    F: FnMut(EE) -> E, 
[src]

Create a new event handler that first applies the given function to the event and then lets the “self” event handler handle the event.

Example

use rsynth::event::EventHandler;
use rsynth::event::EventHandlerExt;

struct Printer;
impl EventHandler<u32> for Printer {
    fn handle_event(&mut self,event: u32) {
        println!("{}", event)
    }
}

fn main() {
    let mut printer = Printer;
    printer.handle_event(3); // Prints "3"
    let mut increased_printer = printer.map(|i| i+1_u32);
    increased_printer.handle_event(3); // Prints "4"
}
Loading content...

Implementors

impl<T: ?Sized, E> EventHandlerExt<E> for T where
    T: EventHandler<E>, 
[src]

Loading content...