EfficientStringBuilder

Struct EfficientStringBuilder 

Source
pub struct EfficientStringBuilder { /* private fields */ }
Expand description

Memory-efficient string builder with size hints

A string builder that allows efficient construction of strings by appending content incrementally, with optional capacity hints for better performance.

§Examples

use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::with_capacity(100);
builder.append("Hello, ");
builder.append("world!");
let result = builder.build();
assert_eq!(result, "Hello, world!");

Implementations§

Source§

impl EfficientStringBuilder

Source

pub fn new() -> Self

Create a new builder

§Returns

A new EfficientStringBuilder with default capacity.

§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let builder = EfficientStringBuilder::new();
Source

pub fn with_capacity(capacity: usize) -> Self

Create a new builder with size hint

§Parameters
  • capacity - The initial capacity to allocate for the string buffer.
§Returns

A new EfficientStringBuilder with the specified capacity.

§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let builder = EfficientStringBuilder::with_capacity(1024);
Source

pub fn append(&mut self, s: &str)

Append a string

§Parameters
  • s - The string to append.
§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::new();
builder.append("Hello");
builder.append(" ");
builder.append("world");
Source

pub fn append_char(&mut self, c: char)

Append a character

§Parameters
  • c - The character to append.
§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::new();
builder.append_char('H');
builder.append_char('i');
builder.append_char('!');
Source

pub fn build(self) -> String

Build the final string

Consumes the builder and returns the constructed string.

§Returns

The final constructed string.

§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::new();
builder.append("Final result");
let result = builder.build();
assert_eq!(result, "Final result");
Source

pub fn len(&self) -> usize

Get current length

§Returns

The current length of the string being built.

§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::new();
builder.append("test");
assert_eq!(builder.len(), 4);
Source

pub fn is_empty(&self) -> bool

Check if the builder is empty

§Returns

true if no content has been added, false otherwise.

§Examples
use trash_utilities::chars::core::EfficientStringBuilder;

let mut builder = EfficientStringBuilder::new();
assert!(builder.is_empty());
builder.append("content");
assert!(!builder.is_empty());

Trait Implementations§

Source§

impl Debug for EfficientStringBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EfficientStringBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.