Skip to content

A result type that handles fatal & recoverable errors differently

License

Notifications You must be signed in to change notification settings

42triangles/rich-result

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A richer Result type for Rust

(on crates.io)

Defined as

pub enum Result<T, RE, FE> {
    Ok(T),
    Recoverable(RE),
    Fatal(FE),
}

it can handle recoverable & fatal errors somewhat easily.

Using ? on it, it either diverges with Result::Fatal for a Result::Fatal, or returns a

pub enum LocalResult<T, RE> {
    NoErr(T),
    Handle(RE),
}

which in turn can be used with ? to get the T out of it, or diverge with a Result::Recoverable.

Result from core when used with ? either diverges with Fatal or returns the value in Ok.

Additionally, for a public API surface for example, you can use the Result type from core by stacking it like so: Result<Result<T, RE>, FE>, with all the instances of ? working as expected.

About

A result type that handles fatal & recoverable errors differently

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages