Having these rather contrived type definitions
trait Generic<T> {
fn some(&self) -> T;
}
impl<T> Generic<T> for i32
where
T: Default,
{
fn some(&self) -> T {
T::default()
}
}
I would like to call some method explicitly specifying type T. Below code apparently does not work because the method itself is not generic.
fn main() {
let int: i32 = 45;
println!( "some: {}", int.some<bool>() );
}
What's the right way of calling some?
println!macro accepts generic type. Here is some ideas : play.rust-lang.org/…&int.some() as &boolworks whileint.some() as booldoes not?Tinto a target type, please see: doc.rust-lang.org/reference/expressions/…