use core::fmt;
use crate::{Utf8Bytes, Utf8BytesMut};
pub trait ToUtf8Bytes {
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn to_utf8bytes(&self) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn to_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes;
}
impl<T> ToUtf8Bytes for T
where
T: fmt::Display + ?Sized,
{
fn to_utf8bytes(&self) -> Utf8Bytes {
let mut value = Utf8BytesMut::new();
fmt::Write::write_fmt(&mut value, format_args!("{self}"))
.expect("a formatting trait implementation returned an error");
value.freeze_shared()
}
fn to_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes {
let mut value = Utf8BytesMut::new();
fmt::Write::write_fmt(&mut value, format_args!("{self}"))
.expect("a formatting trait implementation returned an error");
value.freeze_compact()
}
}
pub trait StrExt: private::Sealed {
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn to_lowercase_utf8bytes(&self) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn to_lowercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes;
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn to_uppercase_utf8bytes(&self) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn to_uppercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes;
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn to_ascii_lowercase_utf8bytes(&self) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn to_ascii_lowercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes;
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn to_ascii_uppercase_utf8bytes(&self) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn to_ascii_uppercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes;
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn replace_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn replace_compact_utf8bytes(&self, from: &str, to: &str) -> crate::compact::Utf8Bytes;
#[must_use = "this returns a new Utf8Bytes without modifying the original"]
fn replacen_utf8bytes(&self, from: &str, to: &str, count: usize) -> Utf8Bytes;
#[must_use = "this returns a new compact Utf8Bytes without modifying the original"]
fn replacen_compact_utf8bytes(
&self,
from: &str,
to: &str,
count: usize,
) -> crate::compact::Utf8Bytes;
}
impl StrExt for str {
#[inline]
fn to_lowercase_utf8bytes(&self) -> Utf8Bytes {
self.to_lowercase().into()
}
#[inline]
fn to_lowercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes {
self.to_lowercase().into()
}
#[inline]
fn to_uppercase_utf8bytes(&self) -> Utf8Bytes {
self.to_uppercase().into()
}
#[inline]
fn to_uppercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes {
self.to_uppercase().into()
}
#[inline]
fn to_ascii_lowercase_utf8bytes(&self) -> Utf8Bytes {
self.to_ascii_lowercase().into()
}
#[inline]
fn to_ascii_lowercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes {
self.to_ascii_lowercase().into()
}
#[inline]
fn to_ascii_uppercase_utf8bytes(&self) -> Utf8Bytes {
self.to_ascii_uppercase().into()
}
#[inline]
fn to_ascii_uppercase_compact_utf8bytes(&self) -> crate::compact::Utf8Bytes {
self.to_ascii_uppercase().into()
}
#[inline]
fn replace_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes {
self.replace(from, to).into()
}
#[inline]
fn replace_compact_utf8bytes(&self, from: &str, to: &str) -> crate::compact::Utf8Bytes {
self.replace(from, to).into()
}
#[inline]
fn replacen_utf8bytes(&self, from: &str, to: &str, count: usize) -> Utf8Bytes {
self.replacen(from, to, count).into()
}
#[inline]
fn replacen_compact_utf8bytes(
&self,
from: &str,
to: &str,
count: usize,
) -> crate::compact::Utf8Bytes {
self.replacen(from, to, count).into()
}
}
mod private {
pub trait Sealed {}
impl Sealed for str {}
}