-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cgp-runtime crate with HasRuntime trait * Add RuntimeGetter trait * Add HasAsyncRuntime trait
- Loading branch information
1 parent
42f6e77
commit ff8dc01
Showing
9 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "cgp-runtime" | ||
version = "0.2.0" | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
authors = { workspace = true } | ||
rust-version = { workspace = true } | ||
keywords = { workspace = true } | ||
description = """ | ||
Context-generic programming core component traits | ||
""" | ||
|
||
[dependencies] | ||
cgp-core = { version = "0.2.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod traits; | ||
|
||
pub use traits::*; |
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,7 @@ | ||
use cgp_core::Async; | ||
|
||
use crate::HasRuntimeType; | ||
|
||
pub trait HasAsyncRuntimeType: Async + HasRuntimeType<Runtime: Async> {} | ||
|
||
impl<Context> HasAsyncRuntimeType for Context where Context: Async + HasRuntimeType<Runtime: Async> {} |
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,24 @@ | ||
use core::marker::PhantomData; | ||
|
||
use cgp_core::component::WithProvider; | ||
use cgp_core::field::FieldGetter; | ||
use cgp_core::prelude::*; | ||
|
||
use crate::HasRuntimeType; | ||
|
||
#[cgp_component { | ||
provider: RuntimeGetter, | ||
}] | ||
pub trait HasRuntime: HasRuntimeType { | ||
fn runtime(&self) -> &Self::Runtime; | ||
} | ||
|
||
impl<Context, Provider, Runtime> RuntimeGetter<Context> for WithProvider<Provider> | ||
where | ||
Context: HasRuntimeType<Runtime = Runtime>, | ||
Provider: FieldGetter<Context, RuntimeGetterComponent, Value = Runtime>, | ||
{ | ||
fn runtime(context: &Context) -> &Runtime { | ||
Provider::get_field(context, PhantomData) | ||
} | ||
} |
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,20 @@ | ||
use cgp_core::component::WithProvider; | ||
use cgp_core::prelude::*; | ||
use cgp_core::types::traits::ProvideType; | ||
|
||
#[cgp_component { | ||
name: RuntimeTypeComponent, | ||
provider: ProvideRuntimeType, | ||
}] | ||
pub trait HasRuntimeType { | ||
type Runtime; | ||
} | ||
|
||
pub type RuntimeOf<Context> = <Context as HasRuntimeType>::Runtime; | ||
|
||
impl<Context, Provider, Runtime> ProvideRuntimeType<Context> for WithProvider<Provider> | ||
where | ||
Provider: ProvideType<Context, RuntimeTypeComponent, Type = Runtime>, | ||
{ | ||
type Runtime = Runtime; | ||
} |
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,7 @@ | ||
pub mod has_async_runtime; | ||
pub mod has_runtime; | ||
pub mod has_runtime_type; | ||
|
||
pub use has_async_runtime::*; | ||
pub use has_runtime::*; | ||
pub use has_runtime_type::*; |