Confusion between [T] and &[T]

What's the name of the item [T] so ? What is the usage of [T] exactly ?

[T] is a block of contiguous memory, filled with items of type T. It is rarely referred to by name directly because it needs to be behind a pointer to be useful. That is usually a &[T], commonly referred to as a slice, but could also be other pointer types.

The term "slice" is overloaded, but it is not usually a cause of confusion since it really doesn't come up much. In general, if the word "slice" is used by itself then it means &[T]. If it has some other modifier, then it probably refers to a different pointer type. For example Box<[T]> is a "boxed slice" and Rc<[T]> might be called a "ref-counted slice".

Tags:

Arrays

Slice

Rust