8000 GitHub - limbo-rs/throws: A macro for easy creation per-function errors
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

limbo-rs/throws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Throws

throws! is a macro for easy creation per-function error enums.

Example

throws!(FileDoubleError = Io(io::Error), Parse(ParseIntError));
fn file_double(path: &str) -> Result<i32, FileDoubleError> {
    let mut file = File::open(path)?;
    let mut contents = String::new();

    file.read_to_string(&mut contents)?;
    let n: i32 = contents.trim().parse()?;

    Ok(2 * n)
}

For more, check out the examples directory!

You can run an individual example using cargo run --example example-name.

Installation

If you're using cargo, just add throws to your Cargo.toml:

[dependencies]

throws = "*"

Otherwise, cargo build, and the rlib will be in your target directory.

License

MIT

About

A macro for easy creation per-function errors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0