partial-result

Crates.iopartial-result
lib.rspartial-result
version0.1.0
sourcesrc
created_at2024-01-18 19:22:39.931479
updated_at2024-01-18 19:22:39.931479
descriptionA library for results that return success for non-critical errors.
homepage
repositoryhttps://gitlab.com/manenko/partial-result
max_upload_size
id1104480
size9,432
Oleksandr Manenko (manenko)

documentation

https://docs.rs/partial-result

README

partial-result

The partial-result crate is a Rust library that provides a type representing a partial success, i.e., a result that can contain a failure. This is useful when you need to return a result and a failure, where the failure represents a non-fatal error.

Installation

Add this to your Cargo.toml:

[dependencies]
partial-result = "0.1.0"

Then run cargo build to download and compile the crate.

Usage

Here's a basic example of how to use the PartialResult type:

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(())
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt