devela::all

Trait ExtStr

Source
pub trait ExtStr: Sealed {
    // Required methods
    fn to_box(&self) -> Box<str>;
    fn to_rc(&self) -> Rc<str>;
    fn to_arc(&self) -> Arc<str>;
    fn repeat_into<'input, const CAP: usize>(
        &self,
        n: usize,
        buffer: &'input mut [u8; CAP],
    ) -> &'input str ;
    fn new_counter(buffer: &mut [u8], length: usize, separator: char) -> &str ;
}
Available on crate feature str only.
Expand description

Extension trait providing additional methods for &str.

Required Methods§

Source

fn to_box(&self) -> Box<str>

Converts the string slice into a Box<str>.

Allows single ownership with exact allocation, for when you don’t need to clone or share.

Source

fn to_rc(&self) -> Rc<str>

Converts the string slice into an Rc<str>.

Allows shared ownership with reference counting, reducing memory duplication in single-threaded scenarios.

Source

fn to_arc(&self) -> Arc<str>

Converts the string slice into an Arc<str>.

When you need shared ownership of a string slice across multiple threads.

Source

fn repeat_into<'input, const CAP: usize>( &self, n: usize, buffer: &'input mut [u8; CAP], ) -> &'input str

Repeats a string a given number of times into the provided buffer. and returns a reference to the new &str.

§Examples
use devela::ExtStr;

let mut buf = [0_u8; 12];
let repeated = "ay".repeat_into(3, &mut buf);
assert_eq![repeated, "ayayay"];
§Features

Makes use of the unsafe_str feature if enabled.

For the const version see Str::repeat_into.

Source

fn new_counter(buffer: &mut [u8], length: usize, separator: char) -> &str

Returns a &str backed by a buffer, where you always know each character’s position.

A counter string is a graduated string of arbitrary length, with a separator positioned after the immediately preceding number.

§Examples
use devela::ExtStr;

let mut buf = [0; 15];
assert_eq!("2*4*6*8*11*14*", str::new_counter(&mut buf, 14, '*'));
assert_eq!("_3_5_7_9_12_15_", str::new_counter(&mut buf, 15, '_'));
§Panics

Panics if buffer.len() < length, or if !char.is_ascii().

§Features

Makes use of the unsafe_str feature if enabled.

For the const version see Str::new_counter.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ExtStr for str

Source§

fn to_box(&self) -> Box<str>

Source§

fn to_rc(&self) -> Rc<str>

Source§

fn to_arc(&self) -> Arc<str>

Source§

fn repeat_into<'input, const CAP: usize>( &self, n: usize, buffer: &'input mut [u8; CAP], ) -> &'input str

Source§

fn new_counter(buffer: &mut [u8], length: usize, separator: char) -> &str

Implementors§