I have below generic trait:
trait A<T> {
fn foo(&self) -> T;
}
I have following struct which implements trait A
for String
and usize
:
struct S;
impl A<String> for S {
fn foo(&self) -> String {
String::from("Hello world")
}
}
impl A<usize> for S {
fn foo(&self) -> usize {
37
}
}
When I call method foo
, I can specify type to the variable and that works:
let value: usize = s.foo();
But how can I do the same thing with turbofish operator?
I tried following without success:
let text = s::<usize>.foo();
let text = s.foo::<usize>();
let text = s.::<usize>foo();
How do I use this operator instead of providing the type to the variable?