pub trait ExtString: Sealed {
// Required methods
fn to_box(self) -> Box<str>;
fn to_rc(self) -> Rc<str>;
fn to_arc(self) -> Arc<str>;
fn new_counter(length: usize, separator: char) -> String ⓘ;
}
str
and alloc
only.Expand description
Extension trait providing additional methods for String
.
Required Methods§
Sourcefn to_box(self) -> Box<str>
fn to_box(self) -> Box<str>
Converts the string into a Box<str>
.
Allows single ownership with exact allocation, for when you don’t need to clone or share.
Sourcefn to_rc(self) -> Rc<str>
fn to_rc(self) -> Rc<str>
Converts the string into an Rc<str>
.
Allows shared ownership with reference counting, reducing memory duplication in single-threaded scenarios.
Sourcefn to_arc(self) -> Arc<str>
fn to_arc(self) -> Arc<str>
Converts the string into an Arc<str>
.
When you need shared ownership of a string slice across multiple threads.
Sourcefn new_counter(length: usize, separator: char) -> String ⓘ
fn new_counter(length: usize, separator: char) -> String ⓘ
Returns a String
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::ExtString;
assert_eq!("2*4*6*8*11*14*", String::new_counter(14, '*'));
assert_eq!("_3_5_7_9_12_15_", String::new_counter(15, '_'));
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.