Confusion around Sizedness bound for trait objects #50
-
Hi, long-time reader, first-time poster :) I got confused by two apparently conflicting bits in your whirlwind tour on Rust stdlib traits. In the chapter on subtraits and supertraits, you mention that only types can implement traits. Then, in the chapter on sizedness, you mention that all traits have an implicit trait Trait: ?Sized {} Which, given that only types can implement traits according to the chapter on subtraits and supertraits, would be desugared into something like this: trait Trait where Self: ?Sized {} Now, to me that implies that wnenever I would implement any trait for a type, that type would automatically gain the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think your confusion might stem from how you're interpreting In short: some types are |
Beta Was this translation helpful? Give feedback.
I think your confusion might stem from how you're interpreting
?Sized
. So if?Sized
meant "is not sized" then yes. as an auto-bound on all trait impls it would not make sense since a lot of types are sized, however what it actually means is "may not be sized" and any type may or may not be sized, just like any boolean may be true or may be false :)In short: some types are
Sized
, some are types!Sized
, and all types are?Sized
, since?Sized
is the superset ofSized
+!Sized
. Does that answer you…