#beginner #error-handling #toml #top #go #add

beginnerror

A simple error-handling crate for beginners

1 unstable release

0.1.2 Sep 18, 2023
0.1.1 Sep 18, 2023
0.1.0 Sep 18, 2023

#9 in #beginner

Download history 1/week @ 2024-02-14 6/week @ 2024-02-21 2/week @ 2024-02-28 29/week @ 2024-03-27 42/week @ 2024-04-03

71 downloads per month

MIT license

2KB

Beginnerror

A simple error handling crate for beginners.

Quickstart

Go ahead and add the dependancy to your Cargo.toml so you can use the crate in your rust code. Then, you can use it at the top of your code:

use beginnerror::*;

Now, in your functions, you can use the Result<> to handle errors and use the ? operator.

fn getinput() -> Result<String> {
    let mut buffer = String::new();
    print!("What is your name? -> ")
    std::io::stdin.read_line(&mut buffer)?;
    Ok(buffer.to_string())
}

Then, you can handle the result.

fn main() {
    let res = getinput();
    match res {
        Ok(name) => println!("Hello, {}", name),
        Err(e) => handlerror(e.to_string());
    }
}

Simple enough, right?

No runtime deps