What are the terminologies of v[t], &v[t], trait, &trait?

When we say slice or slice type, it's &v[t] or v[t]?
What we say trait or trai type, it's trait or &trait?

The official book says slice type is &v[t], but error doc says " in a slice type like [u32]".

It's really confusing.

There's no need to cross-post this to both forums. Be patient.

1 Like

The main source of truth is language reference:

A slice is a dynamically sized type representing a 'view' into a sequence of elements of type T . The slice type is written as [T] .

To use a slice type it generally has to be used behind a pointer for example as:

  • &[T] , a 'shared slice', often just called a 'slice', it doesn't own the data it points to, it borrows it.
  • &mut [T] , a 'mutable slice', mutably borrows the data it points to.
  • Box<[T]> , a 'boxed slice'

As for trait, we have traits and trait objects. Trait objects (Trait, dyn Trait, ...) are dynamicaly sized types, so they must accessed behind some kind of indirection (reference, box, etc.). The topic about it in reference is here

Sorry @H2CO3. I just found that ther was a document sub module which was more suitable for this question.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.