StringBuilder

Struct StringBuilder 

Source
pub struct StringBuilder<I = ()> { /* private fields */ }
Expand description

A string builder.

This builder is designed to allow building strings incrementally. This can simplify certain patterns of string construction by removing the need to manually manage a temporary string buffer, clearing it after building the resulting string, and so on.

§Limits

The builder can be configured to limit the overall length of the strings it builds.

§Interning

The builder supports providing an interner that is used to intern the finalized string. This allows for efficiently building strings, reusing the intermediate buffer in between before eventually interning the string.

Implementations§

Source§

impl StringBuilder<()>

Source

pub fn new() -> Self

Creates a new StringBuilder.

No limit is set for the strings built by this builder.

Source

pub fn with_limit(limit: usize) -> Self

Creates a new StringBuilder with the given limit.

Strings that exceed the limit will be discarded.

Source§

impl<I> StringBuilder<I>

Source

pub fn with_interner<I2>(self, interner: I2) -> StringBuilder<I2>
where I2: Interner,

Configures this builder with the given interner.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer of the builder is empty.

Source

pub fn len(&self) -> usize

Returns the length of the buffer of the builder.

Source

pub fn available(&self) -> usize

Returns the available space in the buffer of the builder.

Source

pub fn clear(&mut self)

Clears the buffer of the builder.

Source

pub fn push(&mut self, c: char) -> Option<()>

Pushes a character into the builder.

Returns None if the buffer limit would be exceeded by writing the character.

Source

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

Pushes a string fragment into the builder.

Returns None if the buffer limit would be exceeded by writing the string.

Source

pub fn as_str(&self) -> &str

Returns a references to the current string.

Source§

impl<I> StringBuilder<I>
where I: Interner,

Source

pub fn try_intern(&mut self) -> Option<MetaString>

Attempts to build and intern the string.

Returns None if the string exceeds the configured limit or if it cannot be interned.

Trait Implementations§

Source§

impl Write for StringBuilder

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<I> Freeze for StringBuilder<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for StringBuilder<I>
where I: RefUnwindSafe,

§

impl<I> Send for StringBuilder<I>
where I: Send,

§

impl<I> Sync for StringBuilder<I>
where I: Sync,

§

impl<I> Unpin for StringBuilder<I>
where I: Unpin,

§

impl<I> UnwindSafe for StringBuilder<I>
where I: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Track for T

§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more