diff --git a/sehn/src/utils/writer.rs b/sehn/src/utils/writer.rs index 4a70ba3..e283ee6 100644 --- a/sehn/src/utils/writer.rs +++ b/sehn/src/utils/writer.rs @@ -11,7 +11,10 @@ impl From for GenericBufferWriter where T: GenericWriteBuffer + GenericReadBuffer { fn from(buf: T) -> Self { - Self { buf } + let mut gen_buf = Self { buf }; + // Ensure the buffer is empty. + gen_buf.clear(); + gen_buf } } @@ -22,10 +25,6 @@ impl GenericBufferWriter self.buf } - pub fn clear(&mut self) { - self.buf.clear(); - } - pub fn as_str(&self) -> &str { unsafe { core::str::from_utf8_unchecked(self.buf.as_slice()) } } @@ -34,6 +33,11 @@ impl GenericBufferWriter pub fn to_string(self) -> String { unsafe { String::from_utf8_unchecked(self.buf.to_vec()) } } + + #[inline] + pub fn clear(&mut self) { + self.buf.clear(); + } } impl Write for &mut GenericBufferWriter