thedes_tui_core/input/
device.rs

1use std::{fmt, time::Duration};
2
3use thiserror::Error;
4use tokio::io;
5
6use crate::event::InternalEvent;
7
8pub mod native;
9pub mod null;
10
11#[cfg(feature = "testing")]
12pub mod mock;
13
14#[derive(Debug, Error)]
15pub enum Error {
16    #[error(transparent)]
17    Io(#[from] io::Error),
18}
19
20pub trait InputDevice: fmt::Debug + Send + Sync {
21    fn blocking_read(
22        &mut self,
23        timeout: Duration,
24    ) -> Result<Option<InternalEvent>, Error>;
25}
26
27impl<'a, T> InputDevice for &'a mut T
28where
29    T: InputDevice + ?Sized,
30{
31    fn blocking_read(
32        &mut self,
33        timeout: Duration,
34    ) -> Result<Option<InternalEvent>, Error> {
35        (**self).blocking_read(timeout)
36    }
37}
38
39impl<T> InputDevice for Box<T>
40where
41    T: InputDevice + ?Sized,
42{
43    fn blocking_read(
44        &mut self,
45        timeout: Duration,
46    ) -> Result<Option<InternalEvent>, Error> {
47        (**self).blocking_read(timeout)
48    }
49}