xwt_dyn/utils/
traits.rs

1//! Utility traits.
2
3use xwt_core::utils::maybe;
4
5pub mod maybe_send {
6    use super::*;
7
8    pub trait Future<T>: core::future::Future<Output = T> + maybe::Send {}
9    pub trait Error: core::error::Error + maybe::Send {}
10    pub trait Any: core::any::Any + maybe::Send {}
11
12    impl<X, T> Future<T> for X where X: core::future::Future<Output = T> + maybe::Send {}
13    impl<X> Error for X where X: core::error::Error + maybe::Send {}
14    impl<X> Any for X where X: core::any::Any + maybe::Send {}
15
16    crate::boxed!();
17}
18
19pub mod maybe_send_sync {
20    use super::*;
21
22    pub trait Future<T>: core::future::Future<Output = T> + maybe::Send + maybe::Sync {}
23    pub trait Error: core::error::Error + maybe::Send + maybe::Sync {}
24    pub trait Any: core::any::Any + maybe::Send + maybe::Sync {}
25
26    impl<X, T> Future<T> for X where X: core::future::Future<Output = T> + maybe::Send + maybe::Sync {}
27    impl<X> Error for X where X: core::error::Error + maybe::Send + maybe::Sync {}
28    impl<X> Any for X where X: core::any::Any + maybe::Send + maybe::Sync {}
29
30    crate::boxed!();
31}
32
33#[macro_export]
34macro_rules! boxed {
35    () => {
36        mod boxed {
37            use alloc::boxed::Box;
38
39            pub type BoxedFuture<'a, T> = core::pin::Pin<Box<dyn super::Future<T> + 'a>>;
40            pub type BoxedError<'a> = Box<dyn super::Error + 'a>;
41            pub type BoxedAny<'a> = Box<dyn super::Any + 'a>;
42        }
43        pub use boxed::*;
44    };
45}