You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think you ever cover what a non-Sized type, aka dynamically sized type (DST), is.
Here you call &str and &[u8] "scalar types", and... while the reference is, I suppose... the underlying (DST) slice contains multiple values, so I found their inclusion surprising.
Then later on you refer to &[T] as a slice. This is common nomenclature, but I feel it's worth pointing out that a [T] is more properly the slice, it is dynamically sized, and this is why you typically see it behind a reference (or other pointer like in a Box). And then on this page you could say a str is basically a [u8] with invariants (valid UTF8 encoding).
Incidentally, that page says there are two Rust string types, but there are many others, such as Arc<str> or Cow<'_, str>.
Recursive data types or data types with dynamic sizes need to use a Box
But that's incorrect:
There are no dynamic sizes here in Rust terminology; List<T> has a static size
If you attempt to write List without the Box, it has infinite size -- but still not dynamic
Slices have dynamic sizes but don't need a Box
When you get around to trait objects, you can mention that they're DSTs too, and that's why you typically see them in a Box (but may also seem them behind a reference, in an Arc, ...).
The text was updated successfully, but these errors were encountered:
I don't think you ever cover what a non-
Sized
type, aka dynamically sized type (DST), is.Here you call
&str
and&[u8]
"scalar types", and... while the reference is, I suppose... the underlying (DST) slice contains multiple values, so I found their inclusion surprising.Then later on you refer to
&[T]
as a slice. This is common nomenclature, but I feel it's worth pointing out that a[T]
is more properly the slice, it is dynamically sized, and this is why you typically see it behind a reference (or other pointer like in aBox
). And then on this page you could say astr
is basically a[u8]
with invariants (valid UTF8 encoding).Incidentally, that page says there are two Rust string types, but there are many others, such as
Arc<str>
orCow<'_, str>
.Then later on you say
But that's incorrect:
List<T>
has a static sizeList
without theBox
, it has infinite size -- but still not dynamicBox
When you get around to trait objects, you can mention that they're DSTs too, and that's why you typically see them in a
Box
(but may also seem them behind a reference, in anArc
, ...).The text was updated successfully, but these errors were encountered: