Skip to main content

StringBuilder

Trait StringBuilder 

Source
pub trait StringBuilder<'a>: Sized {
    // Required methods
    fn push_str(&mut self, s: &'a str);
    fn push_char(&mut self, c: char);
    fn from_str(s: &'a str) -> Self;

    // Provided method
    fn empty() -> Self { ... }
}
Expand description

Helper trait for parsing strings with escape sequences. Allows for returning borrowed strings without any allocation if there are no escape sequences, or for recognizing strings without doing actual parsing / allocation.

Required Methods§

Source

fn push_str(&mut self, s: &'a str)

Add a borrowed string to the back of this string

Source

fn push_char(&mut self, c: char)

Add a char to the back of this string

Source

fn from_str(s: &'a str) -> Self

Create a new instance from a borrowed string

Provided Methods§

Source

fn empty() -> Self

Create a new empty instance

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a> StringBuilder<'a> for ()

The empty tuple can be used as a string builder in cases where it’s only necessary to recognize a string and not to parse it

Source§

fn push_str(&mut self, _s: &'a str)

Source§

fn push_char(&mut self, _c: char)

Source§

fn from_str(_s: &'a str)

Source§

impl<'a> StringBuilder<'a> for String

Strings can, of course, be built

Source§

fn push_str(&mut self, s: &'a str)

Source§

fn push_char(&mut self, c: char)

Source§

fn from_str(s: &'a str) -> Self

Implementors§

Source§

impl<'a> StringBuilder<'a> for KdlString<'a>