pub trait MaybeError {
// Required methods
fn from_err(err: impl Error + 'static) -> Self;
fn err(&self) -> Option<DynamoError>;
// Provided methods
fn is_ok(&self) -> bool { ... }
fn is_err(&self) -> bool { ... }
}Expand description
A trait for types that may contain error information.
This trait allows a type to represent either a successful value or an error state.
It integrates with DynamoError for structured error information.
§Example
ⓘ
use dynamo_runtime::protocols::maybe_error::MaybeError;
use dynamo_runtime::error::DynamoError;
struct MyResponse {
data: Option<String>,
error: Option<DynamoError>,
}
impl MaybeError for MyResponse {
fn from_err(err: impl std::error::Error + 'static) -> Self {
MyResponse {
data: None,
error: Some(DynamoError::from(
Box::new(err) as Box<dyn std::error::Error + 'static>
)),
}
}
fn err(&self) -> Option<DynamoError> {
self.error.clone()
}
}Required Methods§
Sourcefn from_err(err: impl Error + 'static) -> Self
fn from_err(err: impl Error + 'static) -> Self
Construct an instance from an error.
The error is converted to a DynamoError for serialization.
Sourcefn err(&self) -> Option<DynamoError>
fn err(&self) -> Option<DynamoError>
Get the error as a DynamoError if this represents an error state.
Returns Some(DynamoError) if this instance represents an error, None otherwise.
Provided Methods§
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.