Crate beginnerror

source ·
Expand description

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?

Functions

Type Aliases