Skip to main content

Utf8BufMut

Trait Utf8BufMut 

Source
pub trait Utf8BufMut: Utf8Buf {
    // Required methods
    fn try_truncate(&mut self, new_len: usize) -> Result<(), Utf8Error>;
    fn push(&mut self, ch: char);
    fn push_str(&mut self, s: &str);
    fn clear(&mut self);
}
Expand description

Extension trait for mutable UTF-8 validated buffer types.

This trait provides common mutable operations for buffer types that can be modified while maintaining UTF-8 validity.

Required Methods§

Source

fn try_truncate(&mut self, new_len: usize) -> Result<(), Utf8Error>

Truncates at a UTF-8 character boundary.

A length at or beyond the current byte length is a no-op. On failure the buffer is unchanged.

Source

fn push(&mut self, ch: char)

Appends a character to the buffer.

§Examples
use smol_bytes::{Utf8BufMut, Utf8BytesMut};

let mut buf = Utf8BytesMut::new();
buf.push('a');
buf.push('b');
assert_eq!(buf.as_str(), "ab");
Source

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

Appends a string slice to the buffer.

§Examples
use smol_bytes::{Utf8BufMut, Utf8BytesMut};

let mut buf = Utf8BytesMut::new();
buf.push_str("hello");
assert_eq!(buf.as_str(), "hello");
Source

fn clear(&mut self)

Clears the buffer, removing all contents.

§Examples
use smol_bytes::{Utf8BufMut, Utf8BytesMut};

let mut buf = Utf8BytesMut::from("hello");
buf.clear();
assert!(buf.is_empty());

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl Utf8BufMut for Utf8Buffer

Source§

impl Utf8BufMut for Utf8BytesMut

Available on crate features alloc or std only.