I'm trying to implement a trait which contains a generic method.
trait Trait {
fn method<T>(&self) -> T;
}
struct Struct;
impl Trait for Struct {
fn method(&self) -> u8 {
return 16u8;
}
}
I get:
error[E0049]: method `method` has 0 type parameters but its trait declaration has 1 type parameter
--> src/lib.rs:8:5
|
2 | fn method<T>(&self) -> T;
| ------------------------- expected 1 type parameter
...
8 | fn method(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^ found 0 type parameters
How should I write the impl
block correctly?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…