Loading tutorials
Copy and Clone traits come in later chapters.3 min readCopy trait: what it is, which types have it, and how it changes what assignment does.3 min readString moves it. Here you will learn how to make a real duplicate on purpose.2 min readCopy, and Clone one at a time. Here they are compared directly.2 min readClone and Copy to your own types with #[derive], and what the compiler checks when you do.2 min read#[derive(Clone, Copy)] makes a type duplicate on assignment. Here you learn when the compiler refuses that derive, and why.2 min readCopy means implicit bitwise duplication and Clone means explicit duplication with .clone(). Here you will learn how to predict which standard library types h2 min readClone trait, and how .clone() differs from an implicit Copy. Here you will learn what a clone actually does at runtime, so you can tell a cheap clone from an expensive one.3 min readCopy, and Clone from the earlier chapters. It shows how to choose between T: Copy and T: Clone when you write generic functions.2 min readClone and Copy, how moves work, and how to read compiler errors. Here you will implement Clone yourself and learn when that is worth doing.2 min read#[derive(Clone, Copy)] behaves, and why a type holding a String cannot be Copy. Here the question is design: given a new type, should it be Copy, Clone only, or neither?3 min readClone works, how String and Vec own heap memory, and what &mut references allow. It covers Clone::clone_from, a method that copies one value into another that already exists.2 min readClone and Copy differ, and how to read compiler errors and run cargo clippy. It covers the mistakes that appear most often when people write .clone() and the lints that catch them.2 min read