Mention that `Copy` can be derived.

This commit is contained in:
LukeMathWalker 2024-05-14 10:51:45 +02:00
parent 2c044a2567
commit 6235d8c1ed
1 changed files with 12 additions and 0 deletions

View File

@ -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! That'd be a violation of Rust's borrowing rules!
It follows that `&mut T` never implements `Copy`, no matter what `T` is. 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 ## References
- The exercise for this section is located in `exercises/04_traits/11_copy` - The exercise for this section is located in `exercises/04_traits/11_copy`