StringBuilder

Struct StringBuilder 

Source
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>

Source

pub const fn empty() -> Self

Source

pub fn build(self) -> String<L>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn pop(&mut self) -> Option<char>

Source

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.

Source

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.

Source

pub fn push_byte(&mut self, b: u8) -> Result<(), Error>

Source

pub fn push_bytes<S: AsRef<[u8]>>(&mut self, s: S) -> Result<(), Error>

Source

pub fn push_str(&mut self, s: &str) -> Result<(), Error>

Source

pub fn push_char(&mut self, ch: char) -> Result<(), Error>

Trait Implementations§

Source§

impl<const L: usize> Default for StringBuilder<L>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.