Skip to main content

rat_salsa/
poll.rs

1/// Trait for an event-source.
2///
3/// If you need to add your own do the following:
4///
5/// * Implement this trait for a struct that fits.
6///
7pub trait PollEvents<Event, Error>: std::any::Any
8where
9    Event: 'static,
10    Error: 'static,
11{
12    fn as_any(&self) -> &dyn std::any::Any;
13
14    /// Preferred sleep time for this event-source.
15    fn sleep_time(&self) -> Option<Duration> {
16        None
17    }
18
19    /// Poll for a new event.
20    ///
21    /// Events are not processed immediately when they occur. Instead,
22    /// all event sources are polled, the poll state is put into a queue.
23    /// Then the queue is emptied one by one and `read_execute()` is called.
24    ///
25    /// This prevents issues with poll-ordering of multiple sources, and
26    /// one source cannot just flood the app with events.
27    fn poll(&mut self) -> Result<bool, Error>;
28
29    /// Read the event and distribute it.
30    ///
31    /// If you add a new event, that doesn't fit into AppEvents, you'll
32    /// have to define a new trait for your AppState and use that.
33    fn read(&mut self) -> Result<crate::Control<Event>, Error>;
34}
35
36mod crossterm;
37mod quit;
38mod rendered;
39mod thread_pool;
40mod tick;
41mod timer;
42#[cfg(feature = "async")]
43mod tokio_tasks;
44
45pub use crossterm::PollCrossterm;
46pub use quit::PollQuit;
47pub use rendered::PollRendered;
48use std::time::Duration;
49pub use thread_pool::PollTasks;
50pub use tick::PollTick;
51pub use timer::PollTimers;
52#[cfg(feature = "async")]
53pub use tokio_tasks::PollTokio;