From 06264e8cc7d41ced4857c5235fb7f9b727fd8b77 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Thu, 30 May 2024 07:19:33 -0700 Subject: [PATCH] Add a note that shared references are `Copy` (#2107) Add a note to the `Copy` slide noting that shared references are `Copy`. A student asked about this today, and it's something I want to remember to mention in future classes. --- src/memory-management/copy-types.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/memory-management/copy-types.md b/src/memory-management/copy-types.md index 25f5cfb5..6cb434bd 100644 --- a/src/memory-management/copy-types.md +++ b/src/memory-management/copy-types.md @@ -57,4 +57,11 @@ In the above example, try the following: `println!` for `p1`. - Show that it works if you clone `p1` instead. +# More to Explore + +- Shared references are `Copy`/`Clone`, mutable references are not. This is + because rust requires that mutable references be exclusive, so while it's + valid to make a copy of a shared reference, creating a copy of a mutable + reference would violate Rust's borrowing rules. +