多么奇怪的错误:
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
}
Run Code Online (Sandbox Code Playgroud)
错误是:
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`
Run Code Online (Sandbox Code Playgroud) 我有lib.rs:
pub mod genetics {
use std;
pub trait RandNewable {
fn new() -> Self;
}
pub trait Gene : std::fmt::Debug + Copy + Clone + RandNewable {}
#[derive(Debug, Copy, Clone)]
pub struct TraderGene {
cheat: bool,
}
impl RandNewable for TraderGene {
fn new() -> TraderGene {
TraderGene {
cheat: true,
}
}
}
#[derive(Debug)]
pub struct DNA<G: Gene> {
genes: [G; 3],
}
impl <G: Gene> DNA<G> {
pub fn create() -> DNA<G> {
DNA {
genes: [RandNewable::new(), …Run Code Online (Sandbox Code Playgroud) rust ×2