我希望这个函数返回一个错误结果:
fn get_result() -> Result<String, std::io::Error> {
// Ok(String::from("foo")) <- works fine
Result::Err(String::from("foo"))
}
错误信息
error[E0308]: mismatched types
--> src/main.rs:3:17
|
3 | Result::Err(String::from("foo"))
| ^^^^^^^^^^^^^^^^^^^ expected struct `std::io::Error`, found struct `std::string::String`
|
= note: expected type `std::io::Error`
found type `std::string::String`
我很困惑如何在使用预期的结构时打印出错误消息。