|
1 | | -pub use cgp_async_macro::native_async as async_trait; |
2 | | - |
3 | | -/** |
4 | | - This is defined as a convenient constraint alias to |
5 | | - `Sized + Send + Sync + 'static`. |
| 1 | +pub mod traits; |
6 | 2 |
|
7 | | - This constraint is commonly required to be present in almost all associated |
8 | | - types. The `Sized` constraint is commonly required for associated types to be |
9 | | - used as generic parameters. The `Send + Sync + 'static` constraints are |
10 | | - important for the use of async functions inside traits. |
| 3 | +pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync}; |
11 | 4 |
|
12 | | - Because Rust do not currently natively support the use of async functions |
13 | | - in traits, we use the [`async_trait`] crate to desugar async functions |
14 | | - inside traits into functions returning |
15 | | - `Pin<Box<dyn Future + Send>>`. Due to the additional `Send` and lifetime |
16 | | - trait bounds inside the returned boxed future, almost all values that are |
17 | | - used inside the async functions are required to have types that implement |
18 | | - `Send` and `Sync`. |
19 | | -
|
20 | | - It is also common to require the associated types to have the `'static` |
21 | | - lifetime for them to be used inside async functions, because Rust would |
22 | | - otherwise infer a more restrictive lifetime that does not outlive the |
23 | | - async functions. The `'static` lifetime constraint here really means |
24 | | - that the types implementing `Async` must not contain any lifetime |
25 | | - parameter. |
26 | | -*/ |
27 | | -pub trait Async: Send + Sync + 'static {} |
| 5 | +#[cfg(feature = "async")] |
| 6 | +pub use cgp_async_macro::native_async as async_trait; |
28 | 7 |
|
29 | | -impl<A> Async for A where A: Send + Sync + 'static {} |
| 8 | +#[cfg(not(feature = "async"))] |
| 9 | +pub use cgp_sync::async_trait; |
0 commit comments