Struct StringBuilder

Source
pub struct StringBuilder { /* private fields */ }

Implementations§

Source§

impl StringBuilder

Source

pub fn new() -> StringBuilder

Return a new StringBuilder with default initial capacity.

Source

pub fn with_capacity(size: usize) -> StringBuilder

Return a new StringBuilder with an initial capacity.

Source

pub fn append<T: Vcharsable>(&mut self, buff: T) -> &mut StringBuilder

Add a type that can be viewed as a slice of bytes.

§Example
use rstring_builder::StringBuilder;
let mut builder = StringBuilder::new();
builder.append("some string");
Source

pub fn len(&self) -> usize

Return the current length in chars of the underlying buffer.

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
builder.append("four");
assert_eq!(builder.len(), 4);
builder.append("華文");
assert_eq!(builder.len(), 6);
Source

pub fn delete_at(&mut self, start: usize) -> &mut StringBuilder

Delete chars of index

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
builder.append("abc");
assert_eq!("bc".to_string(), builder.delete_at(0).string());
assert_eq!("b".to_string(), builder.delete_at(1).string());
Source

pub fn delete(&mut self, start: usize, end: usize) -> &mut StringBuilder

Delete chars range

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
builder.append("abc\ndef");
assert_eq!("adef".to_string(), builder.delete(1, 4).string());
assert_eq!("".to_string(), builder.delete(0, builder.len()).string());
Source

pub fn clear(&mut self) -> &mut StringBuilder

Clear string builder.

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
builder.append("abc\ndef");
assert_eq!("".to_string(), builder.clear().string());
Source

pub fn string(&self) -> String

Return String

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
builder.append("abc\ndef");
assert_eq!("abc\ndef".to_string(), builder.string());
Source

pub fn is_empty(&self) -> bool

text builder is empty

§Example
use rstring_builder::StringBuilder;

let mut builder = StringBuilder::new();
assert_eq!(true, builder.is_empty());
builder.append("abc\ndef");
assert_eq!(false, builder.is_empty());

Trait Implementations§

Source§

impl Debug for StringBuilder

Source§

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

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

impl PartialEq for StringBuilder

Source§

fn eq(&self, other: &StringBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToString for StringBuilder

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl Vcharsable for StringBuilder

Source§

fn vechars(&self) -> Vec<char>

Source§

impl StructuralPartialEq for StringBuilder

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.