Skip to content

This crate offers a pair of traits for effortlessly transforming `Option` into `Result`, elegantly converting `Some` values into `Err` while gracefully handling `None` values as `Ok`. Unleash the full potential of Rust's error handling capabilities with these versatile traits.

License

Notifications You must be signed in to change notification settings

cyphersnake/some-to-err

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Some To Err

Crates.io Crates.io License: MIT Build Status Documentation

This crate offers a pair of traits for effortlessly transforming Option into Result, elegantly converting Some values into Err while gracefully handling None values as Ok. Unleash the full potential of Rust's error handling capabilities with these versatile traits.

Usage

use some_to_err::ErrOr;

{
    let some: Option<&str> = Some("Error");
    let result = some.err_or(42);
    assert_eq!(result, Err("Error"));
}

{
    let none: Option<&str> = None;
    let result = none.err_or(42);
    assert_eq!(result, Ok(42));
}
use some_to_err::ErrOrElse;
{
    let input: Option<&str> = None;
    let result = input.err_or_else(|| "Ok");
    assert_eq!(result, Ok("Ok"));
}

{
    let input = Some("Error");
    let result = input.err_or_else(|| "Ok");
    assert_eq!(result, Err("Error"));
}

About

This crate offers a pair of traits for effortlessly transforming `Option` into `Result`, elegantly converting `Some` values into `Err` while gracefully handling `None` values as `Ok`. Unleash the full potential of Rust's error handling capabilities with these versatile traits.

Topics

Resources

License

Stars

Watchers

Forks

Languages