1 unstable release
0.1.2 | Sep 18, 2023 |
---|---|
0.1.1 |
|
0.1.0 |
|
#6 in #ahead
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?