Skip to content

Commit

Permalink
Add CanRaiseAsyncError and CanWrapAsyncError helper traits (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen authored Jan 16, 2025
1 parent fe9100b commit 3581ab5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/cgp-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pub use cgp_component_macro::{
cgp_auto_getter, cgp_component, cgp_getter, cgp_preset, cgp_type, delegate_components,
for_each_replace, replace_with,
};
pub use cgp_error::{CanRaiseError, CanWrapError, HasAsyncErrorType, HasErrorType};
pub use cgp_error::{
CanRaiseAsyncError, CanRaiseError, CanWrapAsyncError, CanWrapError, HasAsyncErrorType,
HasErrorType,
};
pub use cgp_field::{
Char, Cons, Either, FieldGetter, HasField, HasFieldMut, MutFieldGetter, Nil, UseField, Void,
};
Expand Down
5 changes: 3 additions & 2 deletions crates/cgp-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod traits;

pub use traits::{
CanRaiseError, CanWrapError, ErrorOf, ErrorRaiser, ErrorRaiserComponent, ErrorTypeComponent,
ErrorWrapper, ErrorWrapperComponent, HasAsyncErrorType, HasErrorType, ProvideErrorType,
CanRaiseAsyncError, CanRaiseError, CanWrapAsyncError, CanWrapError, ErrorOf, ErrorRaiser,
ErrorRaiserComponent, ErrorTypeComponent, ErrorWrapper, ErrorWrapperComponent,
HasAsyncErrorType, HasErrorType, ProvideErrorType,
};
15 changes: 15 additions & 0 deletions crates/cgp-error/src/traits/has_async_error_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
use cgp_async::Async;

use crate::traits::HasErrorType;
use crate::{CanRaiseError, CanWrapError};

pub trait HasAsyncErrorType: Async + HasErrorType<Error: Async> {}

impl<Context> HasAsyncErrorType for Context where Context: Async + HasErrorType<Error: Async> {}

pub trait CanRaiseAsyncError<SourceError>: HasAsyncErrorType + CanRaiseError<SourceError> {}

impl<Context, SourceError> CanRaiseAsyncError<SourceError> for Context where
Context: HasAsyncErrorType + CanRaiseError<SourceError>
{
}

pub trait CanWrapAsyncError<SourceError>: HasAsyncErrorType + CanWrapError<SourceError> {}

impl<Context, SourceError> CanWrapAsyncError<SourceError> for Context where
Context: HasAsyncErrorType + CanWrapError<SourceError>
{
}
2 changes: 1 addition & 1 deletion crates/cgp-error/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod has_error_type;

pub use can_raise_error::{CanRaiseError, ErrorRaiser, ErrorRaiserComponent};
pub use can_wrap_error::{CanWrapError, ErrorWrapper, ErrorWrapperComponent};
pub use has_async_error_type::HasAsyncErrorType;
pub use has_async_error_type::{CanRaiseAsyncError, CanWrapAsyncError, HasAsyncErrorType};
pub use has_error_type::{ErrorOf, ErrorTypeComponent, HasErrorType, ProvideErrorType};

0 comments on commit 3581ab5

Please sign in to comment.