我获得了一个期望的类型参数,即使我认为我已经返回了正确的类型数据。我正在学习Rust中关于泛型的材料阶段。
错误信息:
struct Cat {
weight: i32,
}
trait Animal{
fn get_weight<T>(&self) -> T;
}
impl Animal for Cat {
fn get_weight<i32>(&self) -> i32 {
self.weight // I got error in here
}
}
fn main() {}
错误信息:
mismatched types
expected type parameter, found i32
note: expected type `i32` (type parameter)
found type `i32` (i32)
expected `i32` because of return type
expected type parameter, found i32