-
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.
Introduce
cgp-type
crate with various refactoring (#23)
* Add cgp-type crate * Add DelegateTo impl type * Implement WithTypeProvider and UseType * Add UseFieldType * Add HasFieldMut trait * Use core::error::Error in cgp-error-std * Derive HasFieldMut in derive(HasField) macro * Organize re-exports * Fix HasFieldMut macro * Rename UseFieldType to UseField * Generalize WithTypeProvider to WithProvider * Reorganize HasFieldMut into its own module * Add FieldGetter traits * Implement FieldGetter for any OutTag for UseField<Tag> * Add UseContext * Make impl DelegateTo for ProvideType use Component::Delegate as type * Revert change to ProvideType implementation * Add changelog
- Loading branch information
1 parent
496252f
commit 3a19aac
Showing
34 changed files
with
301 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog | ||
|
||
## Pre-Release | ||
|
||
- Introduce `cgp-type` crate with various refactoring [#23](https://github.com/contextgeneric/cgp/pull/23) | ||
- Introduce `cgp-type` crate, with the `HasType` component. | ||
- Introduce `FieldGetter` as a manual provider trait for `HasField`. | ||
- Introduce `HasFieldMut` trait to `cgp-field`, and auto derive it in `#[derive(HasField)]`. | ||
- Introduce `DelegateTo` in `cgp-component` as a generalized delegation component. | ||
- Introduce `WithProvider` in `cgp-component` as a generalized provider transformation component. | ||
- Introduce `UseContext` in `cgp-component` for generalized implementation of provider via context. | ||
- Replace `DelegateErrorComponents` in `cgp-error` and replace it with `DelegateTo`. | ||
- Use `core::error::Error` instead of `std::error::Error` in `cgp-error-std`. |
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,3 @@ | ||
use core::marker::PhantomData; | ||
|
||
pub struct DelegateTo<Components>(pub PhantomData<Components>); |
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 delegate_to; | ||
pub mod use_context; | ||
pub mod with_provider; | ||
|
||
pub use delegate_to::DelegateTo; | ||
pub use use_context::{UseContext, WithContext}; | ||
pub use with_provider::WithProvider; |
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,5 @@ | ||
use crate::WithProvider; | ||
|
||
pub struct UseContext; | ||
|
||
pub type WithContext = WithProvider<UseContext>; |
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 @@ | ||
use core::marker::PhantomData; | ||
|
||
pub struct WithProvider<Provider>(pub PhantomData<Provider>); |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
mod can_raise_error; | ||
mod delegate_error; | ||
mod has_error_type; | ||
|
||
pub use can_raise_error::*; | ||
pub use delegate_error::*; | ||
pub use has_error_type::*; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod use_field; |
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,40 @@ | ||
use core::marker::PhantomData; | ||
|
||
use cgp_component::WithProvider; | ||
use cgp_type::traits::has_type::ProvideType; | ||
|
||
use crate::traits::has_field::{FieldGetter, HasField}; | ||
use crate::traits::has_field_mut::{HasFieldMut, MutFieldGetter}; | ||
|
||
pub struct UseField<Tag>(pub PhantomData<Tag>); | ||
|
||
pub type WithField<Tag> = WithProvider<UseField<Tag>>; | ||
|
||
impl<Context, TypeTag, FieldTag, Field> ProvideType<Context, TypeTag> for UseField<FieldTag> | ||
where | ||
Context: HasField<FieldTag, Field = Field>, | ||
{ | ||
type Type = Field; | ||
} | ||
|
||
impl<Context, OutTag, Tag, Field> FieldGetter<Context, OutTag> for UseField<Tag> | ||
where | ||
Context: HasField<Tag, Field = Field>, | ||
{ | ||
type Field = Field; | ||
|
||
fn get_field(context: &Context, _tag: PhantomData<OutTag>) -> &Self::Field { | ||
context.get_field(PhantomData) | ||
} | ||
} | ||
|
||
impl<Context, OutTag, Tag, Field> MutFieldGetter<Context, OutTag> for UseField<Tag> | ||
where | ||
Context: HasFieldMut<Tag, Field = Field>, | ||
{ | ||
type Field = Field; | ||
|
||
fn get_field_mut(context: &mut Context, _tag: PhantomData<OutTag>) -> &mut Self::Field { | ||
context.get_field_mut(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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#![no_std] | ||
|
||
pub mod impls; | ||
pub mod traits; | ||
pub mod types; | ||
|
||
pub use cgp_field_macro::{symbol, HasField}; | ||
pub use traits::HasField; | ||
pub use traits::{FieldGetter, HasField, HasFieldMut, MutFieldGetter}; | ||
pub use types::Char; |
Oops, something went wrong.