File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,39 @@ impl UninitSlice {
136
136
pub fn len ( & self ) -> usize {
137
137
self . 0 . len ( )
138
138
}
139
+
140
+ /// Divides one mutable slice into two at an index.
141
+ ///
142
+ /// The first will contain all indices from `[0, mid)` (excluding the index
143
+ /// `mid` itself) and the second will contain all indices from [mid, len)
144
+ /// (excluding the index `len` itself).
145
+ ///
146
+ /// # Panics
147
+ ///
148
+ /// Panics if `mid > len`.
149
+ ///
150
+ /// # Examples
151
+ ///
152
+ /// ```
153
+ /// use bytes::BufMut;
154
+ ///
155
+ /// let mut data = [0, 1, 2];
156
+ /// let mut slice = &mut data[..];
157
+ /// let chunk = BufMut::chunk_mut(&mut slice);
158
+ ///
159
+ /// let (left, right) = chunk.split_at_mut(2);
160
+ /// left.copy_from_slice(&[3, 4]);
161
+ ///
162
+ /// assert_eq!(data, [3, 4, 2]);
163
+ /// ```
164
+ pub fn split_at_mut ( & mut self , mid : usize ) -> ( & mut UninitSlice , & mut UninitSlice ) {
165
+ let ( left, right) = self . 0 . split_at_mut ( mid) ;
166
+ unsafe {
167
+ let left = UninitSlice :: from_raw_parts_mut ( left. as_mut_ptr ( ) as * mut u8 , left. len ( ) ) ;
168
+ let right = UninitSlice :: from_raw_parts_mut ( right. as_mut_ptr ( ) as * mut u8 , right. len ( ) ) ;
169
+ ( left, right)
170
+ }
171
+ }
139
172
}
140
173
141
174
impl fmt:: Debug for UninitSlice {
You can’t perform that action at this time.
0 commit comments