Crate partial_result
source ·Expand description
A crate that provides a type that represents a partial success, i.e. a result that can contain a failure.
Use this crate if you need to return a result and a failure. The failure can be of any type and represents a non-fatal error.
Examples
use partial_result::{
PartialResult,
PartialResultExt,
PartialSuccess,
};
#[derive(Debug)]
enum CriticalError {
WeAreDoomed(String),
EverythingIsLost(String),
}
#[derive(Debug)]
enum NonCriticalError {
SomethingWentWrong(String),
SomethingElseWentWrong(String),
}
fn do_something() -> PartialResult<u32, NonCriticalError, CriticalError> {
let value = 42;
let failure = NonCriticalError::SomethingWentWrong("Something went wrong".to_string());
PartialResult::partial_success(value, failure)
}
fn main() -> Result<(), CriticalError> {
let result = do_something()?;
println!("Result: {}", result.value);
result.failure.map(|e| println!("WARN: there was an issue during the computation: {:?}", e));
Ok(())
}
Structs
- A type that represents a partial success.
Traits
- A trait that extends
PartialResult<T, F, E>
with additional methods.
Type Aliases
- A type that represents a result, where successful results can contain a failure.