From 473260bfc7deb0a887e71881ab9e14952f6f976f Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Sat, 7 Dec 2024 16:55:56 +0100 Subject: [PATCH] Rename `HasField::Field` to `HasField::Value` (#35) * Rename HasField::Field to HasField::Value * Add changelog --- CHANGELOG.md | 2 ++ crates/cgp-core/src/lib.rs | 9 ++++---- crates/cgp-field/src/impls/use_field.rs | 18 +++++++--------- crates/cgp-field/src/traits/has_field.rs | 22 ++++++++++---------- crates/cgp-field/src/traits/has_field_mut.rs | 15 +++++++------ crates/cgp/src/lib.rs | 3 +-- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ccd5c0..58a6eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Pre-Release +- Rename `HasField::Field` to `HasField::Value` - [#35](https://github.com/contextgeneric/cgp/pull/35) + - Remove `Sized` constraint from `Async` trait - [#34](https://github.com/contextgeneric/cgp/pull/34) - Component pattern improvements - [#24](https://github.com/contextgeneric/cgp/pull/24) diff --git a/crates/cgp-core/src/lib.rs b/crates/cgp-core/src/lib.rs index 01498d6..02000aa 100644 --- a/crates/cgp-core/src/lib.rs +++ b/crates/cgp-core/src/lib.rs @@ -3,8 +3,7 @@ pub mod prelude; pub use cgp_async::{async_trait, Async}; -pub use cgp_component as component; -pub use cgp_error as error; -pub use cgp_field as field; -pub use cgp_inner as inner; -pub use cgp_type as types; +pub use { + cgp_component as component, cgp_error as error, cgp_field as field, cgp_inner as inner, + cgp_type as types, +}; diff --git a/crates/cgp-field/src/impls/use_field.rs b/crates/cgp-field/src/impls/use_field.rs index 597d0b0..61b7b03 100644 --- a/crates/cgp-field/src/impls/use_field.rs +++ b/crates/cgp-field/src/impls/use_field.rs @@ -12,29 +12,27 @@ pub type WithField = WithProvider>; impl ProvideType for UseField where - Context: HasField, + Context: HasField, { type Type = Field; } -impl FieldGetter for UseField +impl FieldGetter for UseField where - Context: HasField, + Context: HasField, { - type Field = Field; + type Value = Value; - fn get_field(context: &Context, _tag: PhantomData) -> &Self::Field { + fn get_field(context: &Context, _tag: PhantomData) -> &Value { context.get_field(PhantomData) } } -impl MutFieldGetter for UseField +impl MutFieldGetter for UseField where - Context: HasFieldMut, + Context: HasFieldMut, { - type Field = Field; - - fn get_field_mut(context: &mut Context, _tag: PhantomData) -> &mut Self::Field { + fn get_field_mut(context: &mut Context, _tag: PhantomData) -> &mut Value { context.get_field_mut(PhantomData) } } diff --git a/crates/cgp-field/src/traits/has_field.rs b/crates/cgp-field/src/traits/has_field.rs index 8999cdb..b4557a5 100644 --- a/crates/cgp-field/src/traits/has_field.rs +++ b/crates/cgp-field/src/traits/has_field.rs @@ -4,36 +4,36 @@ use core::ops::Deref; use cgp_component::UseContext; pub trait HasField { - type Field; + type Value; - fn get_field(&self, tag: PhantomData) -> &Self::Field; + fn get_field(&self, tag: PhantomData) -> &Self::Value; } pub trait FieldGetter { - type Field; + type Value; - fn get_field(context: &Context, tag: PhantomData) -> &Self::Field; + fn get_field(context: &Context, tag: PhantomData) -> &Self::Value; } -impl HasField for Context +impl HasField for Context where Context: Deref, - Target: HasField + 'static, + Target: HasField + 'static, { - type Field = Field; + type Value = Value; - fn get_field(&self, tag: PhantomData) -> &Self::Field { + fn get_field(&self, tag: PhantomData) -> &Self::Value { self.deref().get_field(tag) } } impl FieldGetter for UseContext where - Context: HasField, + Context: HasField, { - type Field = Field; + type Value = Field; - fn get_field(context: &Context, _tag: PhantomData) -> &Self::Field { + fn get_field(context: &Context, _tag: PhantomData) -> &Self::Value { context.get_field(PhantomData) } } diff --git a/crates/cgp-field/src/traits/has_field_mut.rs b/crates/cgp-field/src/traits/has_field_mut.rs index 2eef9a2..0b194ad 100644 --- a/crates/cgp-field/src/traits/has_field_mut.rs +++ b/crates/cgp-field/src/traits/has_field_mut.rs @@ -2,23 +2,22 @@ use core::marker::PhantomData; use core::ops::DerefMut; use crate::traits::has_field::HasField; +use crate::FieldGetter; pub trait HasFieldMut: HasField { - fn get_field_mut(&mut self, tag: PhantomData) -> &mut Self::Field; + fn get_field_mut(&mut self, tag: PhantomData) -> &mut Self::Value; } -pub trait MutFieldGetter { - type Field; - - fn get_field_mut(context: &mut Context, tag: PhantomData) -> &mut Self::Field; +pub trait MutFieldGetter: FieldGetter { + fn get_field_mut(context: &mut Context, tag: PhantomData) -> &mut Self::Value; } -impl HasFieldMut for Context +impl HasFieldMut for Context where Context: DerefMut, - Target: HasFieldMut + 'static, + Target: HasFieldMut + 'static, { - fn get_field_mut(&mut self, tag: PhantomData) -> &mut Self::Field { + fn get_field_mut(&mut self, tag: PhantomData) -> &mut Self::Value { self.deref_mut().get_field_mut(tag) } } diff --git a/crates/cgp/src/lib.rs b/crates/cgp/src/lib.rs index f57f97a..650a3c2 100644 --- a/crates/cgp/src/lib.rs +++ b/crates/cgp/src/lib.rs @@ -1,3 +1,2 @@ -pub use cgp_core as core; pub use cgp_core::prelude; -pub use cgp_extra as extra; +pub use {cgp_core as core, cgp_extra as extra};