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<()>
impl StringBuilder<()>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new StringBuilder
.
No limit is set for the strings built by this builder.
Sourcepub fn with_limit(limit: usize) -> Self
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>
impl<I> StringBuilder<I>
Sourcepub fn with_interner<I2>(self, interner: I2) -> StringBuilder<I2>where
I2: Interner,
pub fn with_interner<I2>(self, interner: I2) -> StringBuilder<I2>where
I2: Interner,
Configures this builder with the given interner.
Sourcepub fn push(&mut self, c: char) -> Option<()>
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§impl<I> StringBuilder<I>where
I: Interner,
impl<I> StringBuilder<I>where
I: Interner,
Sourcepub fn try_intern(&mut self) -> Option<MetaString>
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§
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> 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more