Skip to content

Commit

Permalink
Added set_len method to Buffer (jorgecarleitao#1374)
Browse files Browse the repository at this point in the history
Adding `set_len` enables to change the length value of the buffer.

This is required if `get_mut` changes the length of the buffer.
  • Loading branch information
haixuanTao authored and ritchie46 committed Apr 5, 2023
1 parent c55377c commit 5ba1a3a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ impl<T> Buffer<T> {
self.offset
}

/// # Safety
/// The caller must ensure that the buffer was properly initialized up to `len`.
#[inline]
pub unsafe fn set_len(&mut self, len: usize) {
self.length = len;
}

/// Returns a mutable reference to its underlying [`Vec`], if possible.
///
/// This operation returns [`Either::Right`] iff this [`Buffer`]:
Expand Down

0 comments on commit 5ba1a3a

Please sign in to comment.