From 517d12fd366046a7e76aa79a86dbbd72bb72ff45 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 11 Sep 2023 18:09:01 -0400 Subject: [PATCH] Add unsafe set_size --- src/buf.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/buf.rs b/src/buf.rs index 737a72d..d455a0f 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -75,6 +75,14 @@ impl Buf { } } + /// Set the size of data in this buffer without checking or initializing. + /// This does not check that new_size does not exceed capacity or zero the content + /// of the buffer, so it is unsafe. + #[inline(always)] + pub unsafe fn set_size(&mut self, new_size: usize) { + *self.0 = new_size as u32; + } + /// Attempt to append a slice and return true on success or false if the slice is too big. /// This does the same thing as std::io::Write::write() but just returns a bool. #[inline]