pub struct StringBuilder<const L: usize> { /* private fields */ }Expand description
A builder for the fixed-size String. Offers pushing of single bytes, chars,
and byte-slices into the buffer.
let mut builder = StringBuilder::<5>::empty();
builder.push_char('a');
builder.push_char('б');
assert_eq!(builder.len(), 3);
assert_eq!(builder.pop(), Some('б'));
assert_eq!(builder.len(), 1);
// trying to push beyond the limit is an error
let err = builder.push_bytes(b"qwerty");
assert_eq!(Err(Error::new(5, 7)), err);
assert_eq!(builder.len(), 1);
builder.push_str("bcde");
assert_eq!(builder.len(), 5);
let s = builder.build();
assert_eq!(s, "abcde");Implementations§
Source§impl<const L: usize> StringBuilder<L>
impl<const L: usize> StringBuilder<L>
pub const fn empty() -> Self
pub fn build(self) -> String<L>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn pop(&mut self) -> Option<char>
Sourcepub unsafe fn push_byte_unchecked(&mut self, b: u8)
pub unsafe fn push_byte_unchecked(&mut self, b: u8)
§Safety
It is up to the user to ensure that the byte being pushed will keep the string valid UTF-8.
Sourcepub unsafe fn push_bytes_unchecked(&mut self, s: &[u8])
pub unsafe fn push_bytes_unchecked(&mut self, s: &[u8])
§Safety
It is up to the user to ensure that the bytes being pushed will keep the string valid UTF-8.
pub fn push_byte(&mut self, b: u8) -> Result<(), Error>
pub fn push_bytes<S: AsRef<[u8]>>(&mut self, s: S) -> Result<(), Error>
pub fn push_str(&mut self, s: &str) -> Result<(), Error>
pub fn push_char(&mut self, ch: char) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl<const L: usize> Freeze for StringBuilder<L>
impl<const L: usize> RefUnwindSafe for StringBuilder<L>
impl<const L: usize> Send for StringBuilder<L>
impl<const L: usize> Sync for StringBuilder<L>
impl<const L: usize> Unpin for StringBuilder<L>
impl<const L: usize> UnwindSafe for StringBuilder<L>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more