[][src]Struct sdl2::event::EventSender

pub struct EventSender { /* fields omitted */ }

A sendible type that can push events to the event queue.

Methods

impl EventSender[src]

pub fn push_event(&self, event: Event) -> Result<(), String>[src]

Pushes an event to the event queue.

pub fn push_custom_event<T: Any>(&self, event: T) -> Result<(), String>[src]

Push a custom event

If the event type T was not registered using [EventSubsystem::register_custom_event] (../struct.EventSubsystem.html#method.register_custom_event), this method will panic.

Example: pushing and receiving a custom event

struct SomeCustomEvent {
    a: i32
}

let sdl = sdl2::init().unwrap();
let ev = sdl.event().unwrap();
let mut ep = sdl.event_pump().unwrap();

ev.register_custom_event::<SomeCustomEvent>().unwrap();

let event = SomeCustomEvent { a: 42 };

ev.push_custom_event(event);

let received = ep.poll_event().unwrap(); // or within a for event in ep.poll_iter()
if received.is_user_event() {
    let e2 = received.as_user_event_type::<SomeCustomEvent>().unwrap();
    assert_eq!(e2.a, 42);
}

Auto Trait Implementations

impl RefUnwindSafe for EventSender

impl Send for EventSender

impl Sync for EventSender

impl Unpin for EventSender

impl UnwindSafe for EventSender

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.