diff --git a/src/strings/capped.rs b/src/strings/capped.rs index 7c5bda0..3bf87cd 100644 --- a/src/strings/capped.rs +++ b/src/strings/capped.rs @@ -307,6 +307,28 @@ impl CappedString { unsafe { self.append_bytes(src, len); } } + /// Empties the contents of this `CappedString`. + /// + /// ``` + /// # use libshire::strings::CappedString; + /// # fn main() -> Result<(), libshire::strings::capped::CapacityError> { + /// let mut s = CappedString::<16>::new("hello")?; + /// + /// assert!(!s.is_empty()); + /// assert_eq!(&*s, "hello"); + /// + /// s.clear(); + /// + /// assert!(s.is_empty()); + /// assert_eq!(&*s, ""); + /// # Ok(()) + /// # } + /// ``` + #[inline] + pub fn clear(&mut self) { + self.len = 0; + } + /// Returns a string slice pointing to the underlying string data. #[inline] #[must_use]