How to work with custom string errors in rust?

73 Views Asked by At

How can I return my own string errors in rust?

fn main() -> std::io::Result<(), std::io::Error> {
    let a = 30;
    if a == 10 {
        println!("ten");
    } else if a == 20 {
        println!("twenty");
    } else {
        Err("Not ten or twenty".to_string())
    }
    Ok(())
}

This gives

| fn main()->std::io::Result<(),std::io::Error>{
| 

                          ^^^^^^^^^^^^^^ unexpected type argument
0

There are 0 best solutions below