Struct hookmap_core::common::handler::HandlerFunction[][src]

pub struct HandlerFunction<E> { /* fields omitted */ }
Expand description

An optional input event handler.

Implementations

Creates a new HandlerFunction<E> with None.

Examples

use hookmap_core::{HandlerFunction, KeyboardEvent};
let handler = HandlerFunction::<KeyboardEvent>::new();

Registers a callback function.

Examples

use hookmap_core::{EventBlock, HandlerFunction, KeyboardEvent};

let mut handler = HandlerFunction::<KeyboardEvent>::new();
handler.register_handler(|e| {
    println!("Event target: {:?}", e.target);
    println!("Event action: {:?}", e.action);
    EventBlock::Unblock
});

Returns true if the HandlerFunction registers a callback function.

Examples

use hookmap_core::{EventBlock, HandlerFunction, KeyboardEvent};

let mut handler = HandlerFunction::<KeyboardEvent>::new();
assert!(!handler.is_handler_registered());

handler.register_handler(|_| EventBlock::Unblock);
assert!(handler.is_handler_registered());

Calls a registered handler and returns value returned by the handler.

Panics

Panics if the handler has not yet been registered.

Examples

use hookmap_core::{ButtonAction, ButtonEvent, EventBlock, HandlerFunction, Key, KeyboardEvent};

let mut handler = HandlerFunction::<KeyboardEvent>::new();
handler.register_handler(|_| EventBlock::Block);
let event_block = handler.emit(ButtonEvent::new(Key::A, ButtonAction::Press));
assert_eq!(event_block, EventBlock::Block);

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.