Skip to main content

ImmutableStringBuilder

Struct ImmutableStringBuilder 

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

Source

pub fn new() -> Result<Self, ImmutableStringError>

Creates a new ImmutableStringBuilder. This allocates an initial buffer under the hood.

§Errors

For details see ImmutableStringError.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<ImmutableString<TAllocator>, ImmutableStringError>

Builds a new instance of ImmutableString out of the builder.

§Errors

For details see ImmutableStringError.

Trait Implementations§

Source§

impl<TAllocator: Allocator> ReprC for ImmutableStringBuilder<TAllocator>

Source§

const CHECK: ()

This field is used for const checks only.

Auto Trait Implementations§

§

impl<TAllocator> Freeze for ImmutableStringBuilder<TAllocator>
where TAllocator: Freeze,

§

impl<TAllocator> RefUnwindSafe for ImmutableStringBuilder<TAllocator>
where TAllocator: RefUnwindSafe,

§

impl<TAllocator> Send for ImmutableStringBuilder<TAllocator>

§

impl<TAllocator> Sync for ImmutableStringBuilder<TAllocator>

§

impl<TAllocator> Unpin for ImmutableStringBuilder<TAllocator>
where TAllocator: Unpin,

§

impl<TAllocator> UnsafeUnpin for ImmutableStringBuilder<TAllocator>
where TAllocator: UnsafeUnpin,

§

impl<TAllocator> UnwindSafe for ImmutableStringBuilder<TAllocator>
where TAllocator: 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, 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.