#[cfg(feature = "alloc")]
use crate::{Arc, Box, Rc, Str, String};
#[cfg(feature = "alloc")]
trait Sealed {}
#[cfg(feature = "alloc")]
impl Sealed for String {}
#[doc = crate::_tags!(text)]
#[expect(private_bounds, reason = "Sealed")]
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(notable_trait, cfg(feature = "alloc")))]
pub trait StringExt: Sealed {
fn to_box(self) -> Box<str>;
fn to_rc(self) -> Rc<str>;
fn to_arc(self) -> Arc<str>;
#[must_use]
fn new_counter(length: usize, separator: char) -> String;
}
#[cfg(feature = "alloc")]
impl StringExt for String {
fn to_box(self) -> Box<str> {
self.into_boxed_str()
}
fn to_rc(self) -> Rc<str> {
Rc::from(self)
}
fn to_arc(self) -> Arc<str> {
Arc::from(self)
}
fn new_counter(length: usize, separator: char) -> String {
#[cfg(any(feature = "safe_text", not(feature = "unsafe_str")))]
{
let mut buf = crate::vec_![0u8; length];
let s = Str::new_counter(&mut buf, length, separator);
let len = s.len();
buf.truncate(len);
String::from_utf8(buf).expect("counter string is guaranteed ASCII")
}
#[cfg(all(not(feature = "safe_text"), feature = "unsafe_str"))]
{
let mut s = String::with_capacity(length);
unsafe {
let buf = s.as_mut_vec();
buf.resize(length, 0);
let out = Str::new_counter(buf, length, separator);
let len = out.len();
buf.truncate(len);
}
s
}
}
}