From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 14 May 2024 08:51:45 +0000 (+0200) Subject: Mention that `Copy` can be derived. X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=6235d8c1ed1d23b9b6d966d90d1b3226c6c9e2bf;p=rust_exercises.git Mention that `Copy` can be derived. --- 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`