#result #peak #peak-result #result-handling

peak-result

A simple trait that extends the standard Result enum to allow you to run some code in case of error or success

2 releases (1 stable)

Uses new Rust 2021

1.0.0 Oct 31, 2022
0.0.1 Oct 31, 2022

#548 in Rust patterns

Download history 50/week @ 2022-10-25 51/week @ 2022-11-01 3/week @ 2022-11-08 3/week @ 2022-11-15 3/week @ 2022-11-22

110 downloads per month

MIT license

5KB
61 lines

peak result

This is a simple trait that extends the standard Result enum to allow you to run some code in case of error or success.

This crate exists because I find it annoying that it's needed to use map_err or map so that I can log the results from my functions. However, maybe people find this issue annoying too, and wish to extend upon this basic functionality that peak-error provides.

Usage

Quickstart

[dependencies]
peak-result = "1.0.0"
use peak_result::Peak;

async fn main() {
    // using `peak_err`
    let result = some_function_that_returns_result()
        .peak_err(|e| tracing::error!("function failed: {e:?}"));

    // using `peak_ok`
    let result = some_function_that_returns_result()
        .peak_ok(|it| tracing::info!("function succeeded: {it:?}"));
}

Contribuiting

Take a look at our contributing guide if you wish to contribute.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in peak-result by you, shall be licensed as MIT, without any additional terms or conditions.

No runtime deps