Is there any significant difference between writing a trait declaration the following two ways?
trait MyTrait: Sized {}
trait MyTrait where Self: Sized {}
Thanks!
Is there any significant difference between writing a trait declaration the following two ways?
trait MyTrait: Sized {}
trait MyTrait where Self: Sized {}
Thanks!
They are completely equivalent. The first is a shorter syntax that means the same as the second.
As stated in the reference book Trait and lifetime bounds - The Rust Reference
Bounds can be provided on any type in a where clause. There are also shorter forms for certain common cases:
- In trait declarations as supertraits:
trait Circle : Shape {}
is equivalent totrait Circle where Self : Shape {}
.- ...
Thanks! I was on that page in the reference before posting this