A contiguous storage by any other name


Talking about contiguous blocks of memory can be frustrating.

  • Vec<T>: Vector (heap-allocated growable)
  • [T; n]: Array (stack-allocated fixed-size)
  • &[T]: Slice
  • &mut [T]: Mutable Slice
  • Box<[T]>: Boxed Slice(?)
  • *const [T]: Raw Slice (?)
  • *mut [T]: Mutable Raw Slice (?)
  • [T]: Unsized Slice(?)

Is this the proper terminology? Are there any I missed? Can we try to settle on some naming here?

Whats with as_string()?


  • Array-like: an owning value that is usable as an ordered sequence of values with known, finite length which presents an interface that allows for O(1) (at worst, amortized O(1)) random access. The length need not be statically-known. Exemplar: [T].

  • Slice-like: a non-owning reference to a contiguous (non-strict) subset of an array-like value. Exemplar: &[T].

I think [T; n] should be qualified as “fixed-size” rather than [T] being qualified as “unsized”. That way, the category exemplars are [T]/&[T], rather than [T; n]/&[T]. This does raise the hairy issue of explaining DST, but then, you have to do that at some point anyway to explain traits.

Also, it should be “borrowed immutable slice” and “borrowed mutable slice” in full, shortened to “slice” and “mutable slice” in practice (to keep people from going mad).

Finally, if there was any logic to the universe, Vec would be called Array, but I suppose we’re just going to have to live with it, now. shakes head sadly


Unsized is a misnomer. The value knows its size, but just the type does not. It’s “un-type-sized”. But we can shorten it to just “an unslice” :slight_smile:


I’m glad that this discussion has come up. Having consistent, clear names would reduce confusion. I would really like to see a guide to contiguous storage types in an easy to find place (like in the book), as I’ve spent too much time trying to figure out the types. (I’m still not totally sure whether there is a standard dynamically-sized non-resizable data-owning contiguous storage type, since all documentation seems to indicate a “slice” must point to an existing structure…)


@kainino that’d be Box<[T]>, although it’s pretty uncommon.