@@ -84,10 +84,27 @@ macro_rules! acquire {
8484///
8585/// Shared references in Rust disallow mutation by default, and `Arc` is no
8686/// exception: you cannot generally obtain a mutable reference to something
87- /// inside an `Arc`. If you need to mutate through an `Arc`, use
88- /// [`Mutex`][mutex], [`RwLock`][rwlock], or one of the [`Atomic`][atomic]
89- /// types.
87+ /// inside an `Arc`. If you need to mutate through an `Arc`, you have several options:
9088///
89+ /// 1. Use interior mutability with synchronization primitives like [`Mutex`][mutex],
90+ /// [`RwLock`][rwlock], or one of the [`Atomic`][atomic] types.
91+ ///
92+ /// 2. Use clone-on-write semantics with [`Arc::make_mut`] which provides efficient mutation
93+ /// without requiring interior mutability. This approach clones the data only when
94+ /// needed (when there are multiple references) and can be more efficient when mutations
95+ /// are infrequent.
96+ ///
97+ /// ```
98+ /// use std::sync::Arc;
99+ ///
100+ /// let mut data = Arc::new(vec![1, 2, 3]);
101+ ///
102+ /// // This will clone the vector only if there are other references to it
103+ /// Arc::make_mut(&mut data).push(4);
104+ ///
105+ /// assert_eq!(*data, vec![1, 2, 3, 4]);
106+ /// ```
107+ ///
91108/// **Note**: This type is only available on platforms that support atomic
92109/// loads and stores of pointers, which includes all platforms that support
93110/// the `std` crate but not all those which only support [`alloc`](crate).
0 commit comments