Struct sdl2::event::EventSender
source · [−]pub struct EventSender { /* private fields */ }
Expand description
A sendible type that can push events to the event queue.
Implementations
sourceimpl EventSender
impl EventSender
sourcepub fn push_event(&self, event: Event) -> Result<(), String>
pub fn push_event(&self, event: Event) -> Result<(), String>
Pushes an event to the event queue.
sourcepub fn push_custom_event<T: Any>(&self, event: T) -> Result<(), String>
pub fn push_custom_event<T: Any>(&self, event: T) -> Result<(), String>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more