mirror of
https://github.com/storytold/winit.git
synced 2026-12-01 02:36:24 +01:00
Stable rustfmt lacks a lot of features resulting in worse formatted code, thus use nightly formatter.
29 lines
791 B
Rust
29 lines
791 B
Rust
//! An event loop proxy.
|
|
|
|
use std::sync::mpsc::SendError;
|
|
|
|
use sctk::reexports::calloop::channel::Sender;
|
|
|
|
use crate::event_loop::EventLoopClosed;
|
|
|
|
/// A handle that can be sent across the threads and used to wake up the `EventLoop`.
|
|
pub struct EventLoopProxy<T: 'static> {
|
|
user_events_sender: Sender<T>,
|
|
}
|
|
|
|
impl<T: 'static> Clone for EventLoopProxy<T> {
|
|
fn clone(&self) -> Self {
|
|
EventLoopProxy { user_events_sender: self.user_events_sender.clone() }
|
|
}
|
|
}
|
|
|
|
impl<T: 'static> EventLoopProxy<T> {
|
|
pub fn new(user_events_sender: Sender<T>) -> Self {
|
|
Self { user_events_sender }
|
|
}
|
|
|
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
|
self.user_events_sender.send(event).map_err(|SendError(error)| EventLoopClosed(error))
|
|
}
|
|
}
|