pub trait ErrorCategory<E> {
type ErrorFunctor<T>: WithError<E>;
// Required methods
fn lift<T>(value: T) -> Self::ErrorFunctor<T>;
fn handle_error<T>(error: E) -> Self::ErrorFunctor<T>;
}Expand description
Trait for types that can lift values and handle errors in a functorial way.
This trait provides a category-theoretic abstraction for error handling, allowing types to be lifted into an error-handling context and errors to be properly propagated.
§Type Parameters
E- The error type that this category handles
§Associated Types
ErrorFunctor<T>- The functor type that wraps values of typeTwith error handling
§Examples
use error_rail::traits::ErrorCategory;
fn example<E>() {
let success: Result<i32, E> = <Result<(), E> as ErrorCategory<E>>::lift(42);
assert!(success.is_ok());
}Required Associated Types§
Sourcetype ErrorFunctor<T>: WithError<E>
type ErrorFunctor<T>: WithError<E>
The functor type that provides error handling for values of type T.
Required Methods§
Sourcefn lift<T>(value: T) -> Self::ErrorFunctor<T>
fn lift<T>(value: T) -> Self::ErrorFunctor<T>
Sourcefn handle_error<T>(error: E) -> Self::ErrorFunctor<T>
fn handle_error<T>(error: E) -> Self::ErrorFunctor<T>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<E> ErrorCategory<E> for Result<(), E>
impl<E> ErrorCategory<E> for Result<(), E>
Implementors§
Source§impl<E> ErrorCategory<E> for Validation<E, ()>
Implementation of ErrorCategory for Validation types.
impl<E> ErrorCategory<E> for Validation<E, ()>
Implementation of ErrorCategory for Validation types.
This allows Validation<E, ()> to act as an error category, where:
liftcreatesValidvalueshandle_errorcreatesInvalidvalues with a single error
§Examples
use error_rail::traits::ErrorCategory;
use error_rail::validation::Validation;
let valid: Validation<String, i32> = <Validation<String, ()>>::lift(42);
assert!(valid.is_valid());
let invalid: Validation<String, i32> = <Validation<String, ()>>::handle_error("error".to_string());
assert!(invalid.is_invalid());