pub struct StrBuf { /* private fields */ }Expand description
Builds a Python string, staying on the cheap path until it cannot.
Every literal goes through this, and adjacent literals are concatenated into one, so the surrogate case has to be reachable from anywhere in a string rather than only at the start. Once one arrives the buffer widens once and never narrows again, because narrowing would mean checking on every push for a case that has already happened.
Implementations§
Source§impl StrBuf
impl StrBuf
pub fn new() -> Self
pub fn push(&mut self, c: char)
pub fn push_str(&mut self, s: &str)
Sourcepub fn push_code_point(&mut self, cp: u32)
pub fn push_code_point(&mut self, cp: u32)
Append one code point, which may be a lone surrogate.
This is the only way into the wide representation, and the caller has already decided the value is a code point rather than a scalar value.
Sourcepub fn push_string(&mut self, other: &Str)
pub fn push_string(&mut self, other: &Str)
Append everything in another string, whichever arm it is in.
pub fn is_empty(&self) -> bool
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Empty the buffer and go back to the narrow representation.
A buffer that widened once did so because of one literal, and the next run it collects has no reason to inherit that.