Loading tutorials
Vec<T> work. It introduces the slice type &[T] and the idea that a slice is a borrowed view of data that something else owns.3 min readVec<T> store their elements. It covers the syntax for creating a slice. Handling bad indices and string slices comes in later chapters.2 min readVec<T> work. You should also know what a slice &[T] is and how range syntax such as &a[1..4] creates one. Here you will learn what happens when an index or range is wrong, and how to choose between two w3 min read&[T] slice type from earlier chapters. It covers how &str follows the same idea as &[T], and why its indices are byte offsets, not character positions.3 min read& and &mut, and how Vec<T> and arrays store elements. It also assumes you have seen the &[T] type and range syntax such as &v[1..3].3 min read& and &mut. It also assumes you know how to build a slice with range syntax such as &v[1..3].3 min read&[T] and range slicing like &v[1..4]. Here you will see how the same ideas apply when a slice lets you change the data it borrows.3 min read&[T] and &mut [T], and how Option and Result work. Slice methods are defined on [T], so they work on arrays, vectors, and any sub-slice. Most of them return borrowed views or lazy iterators, so they don'2 min readmatch and if let on enums, and that you can borrow a slice (&[T]) from an array or Vec. Slice patterns let you test a slice's length and bind its elements in one expression. They work well when the shape of the data decides what the code does.3 min read&[T] and &str to functions, and apply the basic borrowing rules. Here you will see what a slice reference looks like in memory and why the compiler treats [T] differently from [T; N].3 min read&[T] and &str borrow data, how Vec<T> and String own it, and how deref coercion lets &Vec<T> stand in for &[T]. Here you will move data in both directions: from a borrowed view to an owned value, and back.2 min read