-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support async-generic feature flags in cgp-async (#37)
* Add cargo feature flags for cgp-async * Propagate default features for cgp-async * Add full feature to cgp and cgp-core * Fix cgp-error-eyre when default-features = false * Add changelog
- Loading branch information
1 parent
fdeaa90
commit 106990f
Showing
25 changed files
with
137 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,9 @@ | ||
pub use cgp_async_macro::native_async as async_trait; | ||
|
||
/** | ||
This is defined as a convenient constraint alias to | ||
`Sized + Send + Sync + 'static`. | ||
pub mod traits; | ||
|
||
This constraint is commonly required to be present in almost all associated | ||
types. The `Sized` constraint is commonly required for associated types to be | ||
used as generic parameters. The `Send + Sync + 'static` constraints are | ||
important for the use of async functions inside traits. | ||
pub use traits::{Async, MaybeSend, MaybeStatic, MaybeSync}; | ||
|
||
Because Rust do not currently natively support the use of async functions | ||
in traits, we use the [`async_trait`] crate to desugar async functions | ||
inside traits into functions returning | ||
`Pin<Box<dyn Future + Send>>`. Due to the additional `Send` and lifetime | ||
trait bounds inside the returned boxed future, almost all values that are | ||
used inside the async functions are required to have types that implement | ||
`Send` and `Sync`. | ||
It is also common to require the associated types to have the `'static` | ||
lifetime for them to be used inside async functions, because Rust would | ||
otherwise infer a more restrictive lifetime that does not outlive the | ||
async functions. The `'static` lifetime constraint here really means | ||
that the types implementing `Async` must not contain any lifetime | ||
parameter. | ||
*/ | ||
pub trait Async: Send + Sync + 'static {} | ||
#[cfg(feature = "async")] | ||
pub use cgp_async_macro::native_async as async_trait; | ||
|
||
impl<A> Async for A where A: Send + Sync + 'static {} | ||
#[cfg(not(feature = "async"))] | ||
pub use cgp_sync::async_trait; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::traits::r#static::MaybeStatic; | ||
use crate::traits::send::MaybeSend; | ||
use crate::traits::sync::MaybeSync; | ||
|
||
/** | ||
This is defined as a convenient constraint alias to | ||
`Sized + Send + Sync + 'static`. | ||
This constraint is commonly required to be present in almost all associated | ||
types. The `Sized` constraint is commonly required for associated types to be | ||
used as generic parameters. The `Send + Sync + 'static` constraints are | ||
important for the use of async functions inside traits. | ||
Because Rust do not currently natively support the use of async functions | ||
in traits, we use the [`async_trait`] crate to desugar async functions | ||
inside traits into functions returning | ||
`Pin<Box<dyn Future + Send>>`. Due to the additional `Send` and lifetime | ||
trait bounds inside the returned boxed future, almost all values that are | ||
used inside the async functions are required to have types that implement | ||
`Send` and `Sync`. | ||
It is also common to require the associated types to have the `'static` | ||
lifetime for them to be used inside async functions, because Rust would | ||
otherwise infer a more restrictive lifetime that does not outlive the | ||
async functions. The `'static` lifetime constraint here really means | ||
that the types implementing `Async` must not contain any lifetime | ||
parameter. | ||
*/ | ||
pub trait Async: MaybeSend + MaybeSync + MaybeStatic {} | ||
|
||
impl<A> Async for A where A: MaybeSend + MaybeSync + MaybeStatic {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod r#async; | ||
pub mod send; | ||
pub mod r#static; | ||
pub mod sync; | ||
|
||
pub use r#async::Async; | ||
pub use r#static::MaybeStatic; | ||
pub use send::MaybeSend; | ||
pub use sync::MaybeSync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(feature = "send")] | ||
pub use core::marker::Send as MaybeSend; | ||
|
||
#[cfg(not(feature = "send"))] | ||
pub trait MaybeSend {} | ||
|
||
#[cfg(not(feature = "send"))] | ||
impl<T> MaybeSend for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[cfg(feature = "static")] | ||
pub trait MaybeStatic: 'static {} | ||
|
||
#[cfg(feature = "static")] | ||
impl<T: 'static> MaybeStatic for T {} | ||
|
||
#[cfg(not(feature = "static"))] | ||
pub trait MaybeStatic {} | ||
|
||
#[cfg(not(feature = "static"))] | ||
impl<T> MaybeStatic for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(feature = "sync")] | ||
pub use core::marker::Sync as MaybeSync; | ||
|
||
#[cfg(not(feature = "sync"))] | ||
pub trait MaybeSync {} | ||
|
||
#[cfg(not(feature = "sync"))] | ||
impl<T> MaybeSync for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
pub mod delegate_component; | ||
pub mod has_components; | ||
pub mod sync; | ||
|
||
pub use delegate_component::DelegateComponent; | ||
pub use has_components::HasComponents; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,4 @@ description = """ | |
""" | ||
|
||
[dependencies] | ||
cgp-async = { version = "0.1.0" } | ||
cgp-component = { version = "0.1.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters