1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| fn result_test(i: i32) -> Result<&'static str, &'static str> {
if i > 0 { Err("Error") } else { Ok("ok") } }
fn main() { println!("Hello, world!");
let a = result_test(-1);
assert_eq!(a.is_ok(), true);
match a { Ok(v) => {println!("v: {v}")}, Err(e) => {println!("e: {e}")} } }
|
https://doc.rust-lang.org/std/result/enum.Result.html