@@ -84,9 +84,29 @@ 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 do need to mutate through an `Arc`, you have several options:
88+ ///
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+ /// 3. Use [`Arc::get_mut`] when you know your `Arc` is not shared (has a reference count of 1),
98+ /// which provides direct mutable access to the inner value without any cloning.
99+ ///
100+ /// ```
101+ /// use std::sync::Arc;
102+ ///
103+ /// let mut data = Arc::new(vec![1, 2, 3]);
104+ ///
105+ /// // This will clone the vector only if there are other references to it
106+ /// Arc::make_mut(&mut data).push(4);
107+ ///
108+ /// assert_eq!(*data, vec![1, 2, 3, 4]);
109+ /// ```
90110///
91111/// **Note**: This type is only available on platforms that support atomic
92112/// loads and stores of pointers, which includes all platforms that support
@@ -1453,11 +1473,14 @@ impl<T: ?Sized> Arc<T> {
14531473 ///
14541474 /// # Safety
14551475 ///
1456- /// The pointer must have been obtained through `Arc::into_raw`, and the
1457- /// associated `Arc` instance must be valid (i.e. the strong count must be at
1476+ /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1477+ /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1478+ /// The associated `Arc` instance must be valid (i.e. the strong count must be at
14581479 /// least 1) for the duration of this method, and `ptr` must point to a block of memory
14591480 /// allocated by the global allocator.
14601481 ///
1482+ /// [from_raw_in]: Arc::from_raw_in
1483+ ///
14611484 /// # Examples
14621485 ///
14631486 /// ```
@@ -1488,13 +1511,16 @@ impl<T: ?Sized> Arc<T> {
14881511 ///
14891512 /// # Safety
14901513 ///
1491- /// The pointer must have been obtained through `Arc::into_raw`, and the
1492- /// associated `Arc` instance must be valid (i.e. the strong count must be at
1514+ /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1515+ /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1516+ /// The associated `Arc` instance must be valid (i.e. the strong count must be at
14931517 /// least 1) when invoking this method, and `ptr` must point to a block of memory
14941518 /// allocated by the global allocator. This method can be used to release the final
14951519 /// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
14961520 /// released.
14971521 ///
1522+ /// [from_raw_in]: Arc::from_raw_in
1523+ ///
14981524 /// # Examples
14991525 ///
15001526 /// ```
@@ -1806,11 +1832,14 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18061832 ///
18071833 /// # Safety
18081834 ///
1809- /// The pointer must have been obtained through `Arc::into_raw`, and the
1810- /// associated `Arc` instance must be valid (i.e. the strong count must be at
1811- /// least 1) for the duration of this method,, and `ptr` must point to a block of memory
1835+ /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1836+ /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1837+ /// The associated `Arc` instance must be valid (i.e. the strong count must be at
1838+ /// least 1) for the duration of this method, and `ptr` must point to a block of memory
18121839 /// allocated by `alloc`.
18131840 ///
1841+ /// [from_raw_in]: Arc::from_raw_in
1842+ ///
18141843 /// # Examples
18151844 ///
18161845 /// ```
@@ -1850,13 +1879,16 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18501879 ///
18511880 /// # Safety
18521881 ///
1853- /// The pointer must have been obtained through `Arc::into_raw`, the
1854- /// associated `Arc` instance must be valid (i.e. the strong count must be at
1882+ /// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1883+ /// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1884+ /// The associated `Arc` instance must be valid (i.e. the strong count must be at
18551885 /// least 1) when invoking this method, and `ptr` must point to a block of memory
18561886 /// allocated by `alloc`. This method can be used to release the final
18571887 /// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
18581888 /// released.
18591889 ///
1890+ /// [from_raw_in]: Arc::from_raw_in
1891+ ///
18601892 /// # Examples
18611893 ///
18621894 /// ```
0 commit comments