I\'ve come across an odd type inference problem that has me scratching my head a bit.
I\'m implementing a generic trait on a struct for multiple types. I started wit
Pass the type parameter to the trait using a turbofish (::<>
):
assert_eq!("asd", Foo::<&str>::foo(&bar));
You could also use fully-qualified syntax to disambiguate which trait the method belongs to:
// This is "type-qualified" and equivalent to `Foo::<&str>::foo(&bar)`
assert_eq!("asd", <_ as Foo<&str>>::foo(&bar));
// This is "fully qualified"
assert_eq!("asd", <Bar as Foo<&str>>::foo(&bar));