| 262 | /// Panics iff `offset` is larger than `len`. |
| 263 | #[inline] |
| 264 | pub fn advance(&mut self, offset: usize) { |
| 265 | assert!( |
| 266 | offset <= self.length, |
| 267 | "the offset of the new Buffer cannot exceed the existing length: offset={} length={}", |
| 268 | offset, |
| 269 | self.length |
| 270 | ); |
| 271 | self.length -= offset; |
| 272 | // Safety: |
| 273 | // This cannot overflow as |
| 274 | // `self.offset + self.length < self.data.len()` |
| 275 | // `offset < self.length` |
| 276 | self.ptr = unsafe { self.ptr.add(offset) }; |
| 277 | } |
| 278 | |
| 279 | /// Returns a new [Buffer] that is a slice of this buffer starting at `offset`, |
| 280 | /// with `length` bytes. |