From ae5a42fb947d52ab86f5b0110c6e00dea2aae304 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Thu, 26 Jan 2023 12:05:48 +0100 Subject: [PATCH] Adding `set_len` method to Buffer Adding `set_len` enables to change the length value of the buffer. This is required if `get_mut` changes the length of the buffer. --- src/buffer/immutable.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/buffer/immutable.rs b/src/buffer/immutable.rs index 2a6fa2de72e..baefa6aa73e 100644 --- a/src/buffer/immutable.rs +++ b/src/buffer/immutable.rs @@ -153,6 +153,13 @@ impl Buffer { 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 [`Some`] iff this [`Buffer`]: