pub struct ImmutableStringBuilder<TAllocator: Allocator> { /* private fields */ }Expand description
The builder for ImmutableString.
It allows direct writing to the underlying buffer, befaure the data gets sealed as immutable.
§Examples
use osom_lib_strings::immutable::ImmutableStringError;
use osom_lib_strings::immutable::std::StdImmutableStringBuilder;
fn main() -> Result<(), ImmutableStringError> {
let mut builder = StdImmutableStringBuilder::new()?;
builder.try_push("Name: ")?;
builder.try_push("John")?;
let string = builder.build()?;
assert_eq!(string, "Name: John");
Ok(())
}Implementations§
Source§impl<TAllocator: Allocator> ImmutableStringBuilder<TAllocator>
impl<TAllocator: Allocator> ImmutableStringBuilder<TAllocator>
Sourcepub fn new() -> Result<Self, ImmutableStringError>
pub fn new() -> Result<Self, ImmutableStringError>
Creates a new ImmutableStringBuilder. This allocates an initial buffer
under the hood.
§Errors
For details see ImmutableStringError.
Sourcepub fn with_capacity(capacity: Length) -> Result<Self, ImmutableStringError>
pub fn with_capacity(capacity: Length) -> Result<Self, ImmutableStringError>
Creates a new ImmutableStringBuilder with given capacity. This allocates an initial buffer
under the hood.
§Errors
For details see ImmutableStringError.
Sourcepub fn with_allocator(
allocator: TAllocator,
) -> Result<Self, ImmutableStringError>
pub fn with_allocator( allocator: TAllocator, ) -> Result<Self, ImmutableStringError>
Creates a new ImmutableStringBuilder with given allocator. This allocates an initial buffer
under the hood.
§Errors
For details see ImmutableStringError.
Sourcepub fn with_capacity_and_allocator(
capacity: Length,
allocator: TAllocator,
) -> Result<Self, ImmutableStringError>
pub fn with_capacity_and_allocator( capacity: Length, allocator: TAllocator, ) -> Result<Self, ImmutableStringError>
Creates a new ImmutableStringBuilder with given capacity and allocator.
This allocates an initial buffer under the hood.
§Errors
For details see ImmutableStringError.
Sourcepub fn try_push(&mut self, text: &str) -> Result<(), ImmutableStringError>
pub fn try_push(&mut self, text: &str) -> Result<(), ImmutableStringError>
Pushes a new string slice to ImmutableStringBuilder. This copies the passed string to the underlying
buffer. It will also resize the underlying buffer on demand.
§Errors
For details see ImmutableStringError.
Sourcepub fn shrink_to_fit(&mut self) -> Result<(), ImmutableStringError>
pub fn shrink_to_fit(&mut self) -> Result<(), ImmutableStringError>
Shrinks the underlying buffer to match the length of the string exactly. This will likely reallocate the underlying buffer.
§Errors
For details see ImmutableStringError.
Sourcepub fn build(self) -> Result<ImmutableString<TAllocator>, ImmutableStringError>
pub fn build(self) -> Result<ImmutableString<TAllocator>, ImmutableStringError>
Builds a new instance of ImmutableString out of the builder.
§Errors
For details see ImmutableStringError.