Struct OptimizedFormatBuffer

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

High-performance buffer for error formatting with safe optimizations

Implementations§

Source§

impl OptimizedFormatBuffer

Source

pub fn new() -> Self

Creates a new optimized format buffer with default capacity.

Initializes a new OptimizedFormatBuffer with a default capacity of 4KB, which is optimized for typical error formatting scenarios. The buffer uses intelligent growth strategies to minimize memory allocations.

§Returns

A new OptimizedFormatBuffer instance with default capacity.

§Examples
let buffer = OptimizedFormatBuffer::new();
assert_eq!(buffer.as_str(), "");
Source§

impl OptimizedFormatBuffer

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new optimized format buffer with specified capacity.

Initializes a new OptimizedFormatBuffer with a custom initial capacity. This is useful when you have an estimate of the final formatted size and want to avoid reallocations during formatting operations.

§Arguments
  • capacity - The initial capacity for the internal string buffer.
§Returns

A new OptimizedFormatBuffer instance with the specified capacity.

§Examples
let buffer = OptimizedFormatBuffer::with_capacity(8192);
assert_eq!(buffer.as_str(), "");
Source

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

High-performance string appending with optimized growth strategy

Source

pub fn as_str(&self) -> &str

Returns a string slice of the buffer’s contents.

This method provides read-only access to the formatted content within the buffer. The returned string slice is guaranteed to be valid UTF-8 as all input is validated.

§Returns

A string slice containing the current buffer contents.

§Examples
let mut buffer = OptimizedFormatBuffer::new();
buffer.append_optimized("Hello, World!");
assert_eq!(buffer.as_str(), "Hello, World!");
§Performance

This operation has O(1) time complexity and does not involve any allocations.

Source

pub fn clear(&mut self)

Clears the buffer contents while preserving the allocated capacity.

This method efficiently removes all content from the buffer without deallocating the underlying storage. This allows for optimal memory reuse when the buffer will be used again with similar content sizes.

§Examples
let mut buffer = OptimizedFormatBuffer::new();
buffer.append_optimized("Hello, World!");
assert_eq!(buffer.as_str().len(), 13);

buffer.clear();
assert_eq!(buffer.as_str().len(), 0);
assert!(buffer.as_str().is_empty());
§Performance

This operation has O(1) time complexity and preserves allocated capacity for optimal memory reuse patterns.

Source

pub fn append_multiple(&mut self, fragments: &[&str])

Optimized formatting for multiple string fragments

Trait Implementations§

Source§

impl Default for OptimizedFormatBuffer

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.