pub struct Utf8Builder { /* private fields */ }Expand description
A builder for building and validating UTF-8 data from chunks.
Implementations§
Source§impl Utf8Builder
impl Utf8Builder
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty Utf8Builder with a specific capacity.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the given Utf8Builder.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the builder, removing all data but keeping the allocated capacity.
Source§impl Utf8Builder
impl Utf8Builder
Sourcepub const fn is_valid(&self) -> bool
pub const fn is_valid(&self) -> bool
Returns true if there is no pending incomplete character.
Invalid bytes are never stored, so the data in the buffer is always valid UTF-8 when this returns true.
Sourcepub fn finalize(self) -> Result<String, Utf8Error>
pub fn finalize(self) -> Result<String, Utf8Error>
Consumes the builder and returns the built String.
Returns an error if the data ends with an incomplete character.
The data is dropped in that case, so use into_bytes instead if the raw data is still needed.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consumes the builder and returns the raw data, even if it ends with an incomplete character.
Source§impl Utf8Builder
impl Utf8Builder
Sourcepub fn push(&mut self, b: u8) -> Result<(), Utf8Error>
pub fn push(&mut self, b: u8) -> Result<(), Utf8Error>
Pushes a byte.
Returns an error if the byte is not allowed at the current position. Nothing is stored in that case, so a correct byte can still be pushed afterwards.
Sourcepub fn push_str(&mut self, s: &str) -> Result<(), Utf8Error>
pub fn push_str(&mut self, s: &str) -> Result<(), Utf8Error>
Pushes a &str.
Returns an error if there is a pending incomplete character. The builder state is unchanged in that case.
Sourcepub fn push_char(&mut self, c: char) -> Result<(), Utf8Error>
pub fn push_char(&mut self, c: char) -> Result<(), Utf8Error>
Pushes a char.
Returns an error if there is a pending incomplete character. The builder state is unchanged in that case.
Sourcepub fn push_chunk(&mut self, chunk: &[u8]) -> Result<(), Utf8Error>
pub fn push_chunk(&mut self, chunk: &[u8]) -> Result<(), Utf8Error>
Pushes a chunk.
The chunk does not have to be complete UTF-8 data, because a character can be split across chunks. Returns an error if the chunk contains invalid data. In that case, the leading valid part of the chunk is still stored, so the builder remains usable. However, if the error happens while completing a pending incomplete character, nothing is stored.
Trait Implementations§
Source§impl Clone for Utf8Builder
impl Clone for Utf8Builder
Source§fn clone(&self) -> Utf8Builder
fn clone(&self) -> Utf8Builder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more