什么奇怪的错误:结果没有称为“unwrap()”的方法?
use std::collections::BTreeMap;
struct MyStruct1;
struct Error;
fn get_res() -> Result<(MyStruct1, BTreeMap<String, String>), Error> {
Err(Error)
}
fn main() {
let res1 = get_res();
assert!(res1.is_ok());
assert_eq!("just for test", res1.unwrap()); //error
}
的错误是:
error: no method named `unwrap` found for type `std::result::Result<(MyStruct1, std::collections::BTreeMap<std::string::String, std::string::String>), Error>` in the current scope
--> src/main.rs:13:38
|
13 | assert_eq!("just for test", res1.unwrap()); //error
| ^^^^^^
|
= note: the method `unwrap` exists but the following trait bounds were not satisfied: `Error : std::fmt::Debug`
尝试'assert_eq!(res1.unwrap(),“只是为了测试”);' – Virbhadrasinh
可能重复[Result类型没有在范围内实现名为''unwrap \']的方法(http://stackoverflow.com/questions/30787271/result-type-does-not-implementation-method-in-scope-named-unwrap) –