I wrote following code in rust. version is 0.12.0-pre-nightly.
struct Sample<T> {
x: T
}
impl<T> Sample<T> {
pub fn new<T>(v: T) -> Sample<T> {
Sample { x: v }
}
pub fn get<T>(&self) -> T {
self.x
}
}
fn main() {
Sample::new(0i).get(); // expect int 0
}
and got compile error.
hoge.rs:11:9: 11:15 error: mismatched types: expected `T`, found `T` (expected type parameter, found type parameter)
hoge.rs:11 self.x
I cannot figure out by compiler message why sample program cannot be compiled. How can I fix it?