我如何才能根据值习惯性地将一种Result
类型转换为另一种类型?Result
Ok
fn get_res1() -> Result<bool, ()> {
Ok(true)
}
fn get_res2() -> Result<(), String> {
let res = get_res1().map_err(|err| String::from("Execution failed"))?;
// map Ok value to Result type(function return type) based on its value
// Is it possible to combine the below transformation with the above Result type method map_err?
if !res {
return Err(String::from("Operation failed"));
}
Ok(())
}