strings: add CappedString::clear method
This patch implements `CappedString::clear`, which provides an easy way for users to clear the contents of a `CappedString`.
This commit is contained in:
1 parent
119a32840a
commit
383f0ae358
1 file changed
+22
@@ -307,6 +307,28 @@ impl<const N: usize> CappedString<N> {
|
|||||||
unsafe { self.append_bytes(src, len); }
|
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.
|
/// Returns a string slice pointing to the underlying string data.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|||||||
Reference in new issue
Block a user