I have a type whose method I can access through
SomeTrait::<T>::method()
But I don't understand the difference between that and
<SomeTrait<T>>::method()
In C++ I would expect this:
SomeTrait<T>::method()
Are these two different? They both seem to be calling the <T>
specialisation of method
on SomeTrait
.
The C++ syntax cannot be used because it is an ambiguous syntax in Rust: in SomeTrait<T>::method()
, is the first <
a lesser-than operator, or the beginning of a generic parameters list?
The two methods you refer to are used to disambiguate this:
<SomeTrait<T>>
is called the fully qualified syntax
SomeTrait::<T>
is called the turbofish notation (unofficial name).SomeTrait::<T>::method()
and <SomeTrait<T>>::method()
are the same thing in Rust.
Just a style choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With