#extension #utils #result

result-extensions

A simple rust library that provides extensions for the Result<T,E> type

3 stable releases

1.0.2 Sep 20, 2022

#2930 in Rust patterns

26 downloads per month

Apache-2.0

6KB

Result Extensions

An extremely simple library that provides extension traits for the standard Rust library's Result<T, E> type.

This library adds "extension functions" to all Sized values to allow them to be moved into Result types:

use result_extensions::ResultExtensions;

fn result_function(bool: is_err) -> Result<String, String> {
  if is_err {
    "error!".to_string().to_err()
  } else {
    "ok!".to_string().to_ok()
  }
}

lib.rs:

Result Extensions

A simple library that functionally creates Result<T, E> values from arbitrary types.

Usage:

mod some_mod {
use result_extensions::ResultExtensions;
    fn is_greater_than_ten(input: i64) -> Result<bool, String> {
        match input {
            i64::MIN..=0 => {
                "this function does not accept values less than or equal to zero for some reason"
                    .to_string()
                    .to_err()
            }
            1..=9 => false.to_ok(),
            _ => true.to_ok(),
        }
    }
}

No runtime deps

Features