From 6235d8c1ed1d23b9b6d966d90d1b3226c6c9e2bf Mon Sep 17 00:00:00 2001 From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 14 May 2024 10:51:45 +0200 Subject: [PATCH] Mention that `Copy` can be derived. --- book/src/04_traits/11_copy.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/book/src/04_traits/11_copy.md b/book/src/04_traits/11_copy.md index ae70f07..bf26b26 100644 --- a/book/src/04_traits/11_copy.md +++ b/book/src/04_traits/11_copy.md @@ -100,6 +100,18 @@ the same value and modify it in multiple places at the same time. That'd be a violation of Rust's borrowing rules! It follows that `&mut T` never implements `Copy`, no matter what `T` is. +## Implementing `Copy` + +In most cases, you don't need to manually implement `Copy`. +You can just derive it, like this: + +```rust +#[derive(Copy, Clone)] +struct MyStruct { + field: u32, +} +``` + ## References - The exercise for this section is located in `exercises/04_traits/11_copy` -- 2.45.2