Loading tutorials
let b = a; does one of two things, depending on the type of a. It either leaves both variables usable, or it hands the value to b and makes a unusable. The second case is called a move. This chapter explains how moves work, where they happen, and which compiler errors they cause. Th6 min read& and &mut). You should also be able to read a compiler error. Here you will learn what the Copy trait changes about assignment, which types have it, and what rules limit it.5 min readClone trait: what it promises, how .clone() behaves for different types, and where it goes wrong. It assumes you know basic Rust syntax (structs, enums, functions, traits), ownership and borrowing basics, and how to read compiler error messages. The previous chapter showe6 min readCopy, and Clone one at a time. Here we put them next to each other and 6 min readCopy and Clone mean. This one covers how to get them onto your own types with #[derive(...)], what th5 min readCopy makes assignment duplicate a value instead of moving it. This chapter covers the other side: the rules that stop a type 5 min readCopy and Clone, and the rules that decide it. It assumes you know the basics of structs, enums and traits, and that you can read ownership errors such as "borrow of moved value". It also assumes you have seen #[derive(Clone, Copy)]. T5 min readClone and Copy differ. Here the question is practical: when you write .clone(), what work does the program do, and when is that work cheap?6 min readCopy and Clone are and how they differ. Here you will see how to use them as trait bounds on generic code, what each bound promises, and which mistakes come up m6 min read#[derive(...)] attributes and write impl Trait for Type blocks. It also assumes you know how moves differ from copies, and that you know what .clone() does on a String. The chapters on deriving and on the cost of cloning cover those points.6 min readCopy, Clone only, or neither for a new type.6 min readClone and Copy differ, how #[derive(Clone)] works, and that String and Vec own heap memory. The previous chapters showed .clone() creating a new value. This chapter covers clone_from, a second method on the Clone trait that overwrites an existing val6 min readCopy and Clone differ, how to derive them, and what a clone costs for String, Vec, Rc and Arc. It covers the mistakes that appear most often in real code, and the Clippy lints that catch many of them.4 min read