|
17 | 17 | //! assert_eq!(shared4.len(), 60); |
18 | 18 | //! |
19 | 19 | //! for byte in shared1.iter_mut() { *byte = 1u8; } |
20 | | -//! for byte in shared2.iter_mut() { *byte = 2u8; } |
21 | | -//! for byte in shared3.iter_mut() { *byte = 3u8; } |
22 | | -//! for byte in shared4.iter_mut() { *byte = 4u8; } |
23 | 20 | //! |
24 | 21 | //! // memory in slabs [4, 2, 3, 1]: merge back in arbitrary order. |
25 | 22 | //! shared2.try_merge(shared3).ok().expect("Failed to merge 2 and 3"); |
26 | | -//! shared2.try_merge(shared1).ok().expect("Failed to merge 23 and 1"); |
| 23 | +//! shared2.try_merge(shared1.freeze()).ok().expect("Failed to merge 23 and 1"); |
27 | 24 | //! shared4.try_merge(shared2).ok().expect("Failed to merge 4 and 231"); |
28 | 25 | //! |
29 | 26 | //! assert_eq!(shared4.len(), 1024); |
@@ -84,12 +81,12 @@ pub mod arc { |
84 | 81 | } |
85 | 82 | } |
86 | 83 |
|
87 | | - /// Extracts [0, index) into a new `BytesMut` which is returned, updating `self`. |
| 84 | + /// Extracts [0, index) into a new `Bytes` which is returned, updating `self`. |
88 | 85 | /// |
89 | 86 | /// # Safety |
90 | 87 | /// |
91 | 88 | /// This method first tests `index` against `self.len`, which should ensure that both |
92 | | - /// the returned `BytesMut` contains valid memory, and that `self` can no longer access it. |
| 89 | + /// the returned `Bytes` contains valid memory, and that `self` can no longer access it. |
93 | 90 | pub fn extract_to(&mut self, index: usize) -> Bytes { |
94 | 91 |
|
95 | 92 | assert!(index <= self.len); |
@@ -123,11 +120,11 @@ pub mod arc { |
123 | 120 | /// let mut shared3 = shared1.extract_to(100); |
124 | 121 | /// let mut shared4 = shared2.extract_to(60); |
125 | 122 | /// |
126 | | - /// drop(shared1); |
| 123 | + /// drop(shared3); |
127 | 124 | /// drop(shared2); |
128 | 125 | /// drop(shared4); |
129 | | - /// assert!(shared3.try_regenerate::<Vec<u8>>()); |
130 | | - /// assert!(shared3.len() == 1024); |
| 126 | + /// assert!(shared1.try_regenerate::<Vec<u8>>()); |
| 127 | + /// assert!(shared1.len() == 1024); |
131 | 128 | /// ``` |
132 | 129 | pub fn try_regenerate<B>(&mut self) -> bool where B: DerefMut<Target=[u8]>+'static { |
133 | 130 | // Only possible if this is the only reference to the sequestered allocation. |
@@ -191,12 +188,12 @@ pub mod arc { |
191 | 188 |
|
192 | 189 | impl Bytes { |
193 | 190 |
|
194 | | - /// Extracts [0, index) into a new `BytesMut` which is returned, updating `self`. |
| 191 | + /// Extracts [0, index) into a new `Bytes` which is returned, updating `self`. |
195 | 192 | /// |
196 | 193 | /// # Safety |
197 | 194 | /// |
198 | 195 | /// This method first tests `index` against `self.len`, which should ensure that both |
199 | | - /// the returned `BytesMut` contains valid memory, and that `self` can no longer access it. |
| 196 | + /// the returned `Bytes` contains valid memory, and that `self` can no longer access it. |
200 | 197 | pub fn extract_to(&mut self, index: usize) -> Bytes { |
201 | 198 |
|
202 | 199 | assert!(index <= self.len); |
@@ -225,7 +222,7 @@ pub mod arc { |
225 | 222 | /// use timely_bytes::arc::BytesMut; |
226 | 223 | /// |
227 | 224 | /// let bytes = vec![0u8; 1024]; |
228 | | - /// let mut shared1 = BytesMut::from(bytes); |
| 225 | + /// let mut shared1 = BytesMut::from(bytes).freeze(); |
229 | 226 | /// let mut shared2 = shared1.extract_to(100); |
230 | 227 | /// let mut shared3 = shared1.extract_to(100); |
231 | 228 | /// let mut shared4 = shared2.extract_to(60); |
|
0 commit comments