802 B
802 B
name = "Vecs and slices" difficulty = 2 exercises = ["access.md"]
Let's now look at some functions on slices and Vecs. Instead of manualy checking things we will follow the type system using Options and Results we saw earlier.
Slices (`[T]`) represent some memory space containing an arbitrary number of elements of type `T`. Since they don't have a size known at compilation time, we can only access them through pointers, commonly `&[T]` (references to slices).
`Vec<T>` can be seen as [owned](https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html) `[T]`, it means that every function working on a `&[T]` can work on a `&Vec<T>`.