Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical nits: Slices and other DSTs #64

Open
QuineDot opened this issue Dec 26, 2022 · 0 comments
Open

Technical nits: Slices and other DSTs #64

QuineDot opened this issue Dec 26, 2022 · 0 comments

Comments

@QuineDot
Copy link

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>.


Then later on you say

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, ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant