From c545eb3cc73df3b9285e282e7fed8b2492af6edb Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Thu, 8 Aug 2024 13:03:34 +0200 Subject: [PATCH] Remove Async bounds in component traits and macros (#20) --- .../src/derive_component/provider_trait.rs | 3 ++- .../cgp-component-macro-lib/src/tests/derive_component.rs | 2 +- crates/cgp-component/src/traits/delegate_component.rs | 4 +--- crates/cgp-component/src/traits/has_components.rs | 6 ++---- crates/cgp-error/src/can_raise_error.rs | 1 - crates/cgp-error/src/has_error_type.rs | 2 +- crates/cgp-run/src/lib.rs | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/cgp-component-macro-lib/src/derive_component/provider_trait.rs b/crates/cgp-component-macro-lib/src/derive_component/provider_trait.rs index 514df0b..8a3addb 100644 --- a/crates/cgp-component-macro-lib/src/derive_component/provider_trait.rs +++ b/crates/cgp-component-macro-lib/src/derive_component/provider_trait.rs @@ -1,3 +1,4 @@ +use syn::punctuated::Punctuated; use syn::{parse_quote, Ident, ItemTrait, TraitItem}; use crate::derive_component::replace_self_receiver::replace_self_receiver; @@ -42,7 +43,7 @@ pub fn derive_provider_trait( &local_assoc_types, )?; - provider_trait.supertraits = parse_quote!(Async); + provider_trait.supertraits = Punctuated::default(); if !context_constraints.is_empty() { if let Some(where_clause) = &mut provider_trait.generics.where_clause { diff --git a/crates/cgp-component-macro-lib/src/tests/derive_component.rs b/crates/cgp-component-macro-lib/src/tests/derive_component.rs index fe6cac4..5eb987b 100644 --- a/crates/cgp-component-macro-lib/src/tests/derive_component.rs +++ b/crates/cgp-component-macro-lib/src/tests/derive_component.rs @@ -39,7 +39,7 @@ fn test_derive_component_with_const_generic() { pub struct FooComponent; - pub trait FooProvider: Async { + pub trait FooProvider { type Foo; fn foo(context: &Context) -> Self::Foo; diff --git a/crates/cgp-component/src/traits/delegate_component.rs b/crates/cgp-component/src/traits/delegate_component.rs index a144e76..d346d8f 100644 --- a/crates/cgp-component/src/traits/delegate_component.rs +++ b/crates/cgp-component/src/traits/delegate_component.rs @@ -1,5 +1,3 @@ -use cgp_async::Async; - -pub trait DelegateComponent: Async { +pub trait DelegateComponent { type Delegate; } diff --git a/crates/cgp-component/src/traits/has_components.rs b/crates/cgp-component/src/traits/has_components.rs index df06398..0439d56 100644 --- a/crates/cgp-component/src/traits/has_components.rs +++ b/crates/cgp-component/src/traits/has_components.rs @@ -1,5 +1,3 @@ -use cgp_async::Async; - -pub trait HasComponents: Async { - type Components: Async; +pub trait HasComponents { + type Components; } diff --git a/crates/cgp-error/src/can_raise_error.rs b/crates/cgp-error/src/can_raise_error.rs index 9dbba85..ded0344 100644 --- a/crates/cgp-error/src/can_raise_error.rs +++ b/crates/cgp-error/src/can_raise_error.rs @@ -1,4 +1,3 @@ -use cgp_async::Async; use cgp_component::{derive_component, DelegateComponent, HasComponents}; use crate::has_error_type::HasErrorType; diff --git a/crates/cgp-error/src/has_error_type.rs b/crates/cgp-error/src/has_error_type.rs index e446727..edd0d3c 100644 --- a/crates/cgp-error/src/has_error_type.rs +++ b/crates/cgp-error/src/has_error_type.rs @@ -15,7 +15,7 @@ use cgp_component::{derive_component, DelegateComponent, HasComponents}; `Self::Error` type. */ #[derive_component(ErrorTypeComponent, ProvideErrorType)] -pub trait HasErrorType: Async { +pub trait HasErrorType { /** The `Error` associated type is also required to implement [`Debug`]. diff --git a/crates/cgp-run/src/lib.rs b/crates/cgp-run/src/lib.rs index 9840746..cca42f9 100644 --- a/crates/cgp-run/src/lib.rs +++ b/crates/cgp-run/src/lib.rs @@ -11,6 +11,6 @@ use cgp_error::HasErrorType; #[derive_component(RunnerComponent, Runner)] #[async_trait] -pub trait CanRun: HasErrorType { +pub trait CanRun: Async + HasErrorType { async fn run(&self) -> Result<(), Self::Error>; }