[][src]Trait abin::StrBuilder

pub trait StrBuilder<'a> {
    type T: AnyBin;
    fn push(&mut self, segment: impl Into<StrSegment<'a, Self::T>>);
fn build(&mut self) -> AnyStr<Self::T>; fn push_str(&mut self, string: impl Into<AnyStr<Self::T>>) { ... }
fn push_slice(&mut self, string: impl Into<&'a str>) { ... }
fn push_static(&mut self, slice: impl Into<&'static str>) { ... }
fn push_given_string(&mut self, string: impl Into<String>) { ... }
fn push_char(&mut self, chr: char) { ... } }

Trait used to build a string efficiently (with just one allocation & no re-allocation or even without allocation).

use abin::{NewStr, StrSegment, Str, StrBuilder};

let mut builder = NewStr::builder();
builder.push(StrSegment::Static("Hello, "));
builder.push(StrSegment::Static("World!"));
let string : Str = builder.build();

assert_eq!("Hello, World!", string.as_str());

Associated Types

type T: AnyBin

The binary type the generated strings are backed by.

Loading content...

Required methods

fn push(&mut self, segment: impl Into<StrSegment<'a, Self::T>>)

fn build(&mut self) -> AnyStr<Self::T>

Builds the string.

Note: After calling this method, the builder will be empty again and can be re-used. We use &mut self here instead of self to make sure the builder is not copied (it's large). I'm not sure how well rust would optimize self here.

Loading content...

Provided methods

fn push_str(&mut self, string: impl Into<AnyStr<Self::T>>)

fn push_slice(&mut self, string: impl Into<&'a str>)

fn push_static(&mut self, slice: impl Into<&'static str>)

fn push_given_string(&mut self, string: impl Into<String>)

fn push_char(&mut self, chr: char)

Loading content...

Implementors

Loading content...