pub trait StrExt: Sealed {
// Required methods
fn to_lowercase_utf8bytes(&self) -> Utf8Bytes;
fn to_lowercase_compact_utf8bytes(&self) -> Utf8Bytes;
fn to_uppercase_utf8bytes(&self) -> Utf8Bytes;
fn to_uppercase_compact_utf8bytes(&self) -> Utf8Bytes;
fn to_ascii_lowercase_utf8bytes(&self) -> Utf8Bytes;
fn to_ascii_lowercase_compact_utf8bytes(&self) -> Utf8Bytes;
fn to_ascii_uppercase_utf8bytes(&self) -> Utf8Bytes;
fn to_ascii_uppercase_compact_utf8bytes(&self) -> Utf8Bytes;
fn replace_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes;
fn replace_compact_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes;
fn replacen_utf8bytes(
&self,
from: &str,
to: &str,
count: usize,
) -> Utf8Bytes;
fn replacen_compact_utf8bytes(
&self,
from: &str,
to: &str,
count: usize,
) -> Utf8Bytes;
}alloc or std only.Expand description
str methods that return default shared or compact UTF-8 bytes.
Methods ending in _utf8bytes return the default shared Utf8Bytes,
retaining heap storage after shrinking. Their _compact_utf8bytes
counterparts return crate::compact::Utf8Bytes, which use inline storage
whenever their contents fit.
This trait is sealed and can only be implemented for str by this crate.
Required Methods§
Sourcefn to_lowercase_utf8bytes(&self) -> Utf8Bytes
fn to_lowercase_utf8bytes(&self) -> Utf8Bytes
Returns the lowercase equivalent as the default shared Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::to_lowercase_compact_utf8bytes when short results should use inline storage.
See str::to_lowercase.
§Examples
use smol_bytes::StrExt;
assert_eq!("RÜST".to_lowercase_utf8bytes().as_str(), "rüst");Sourcefn to_lowercase_compact_utf8bytes(&self) -> Utf8Bytes
fn to_lowercase_compact_utf8bytes(&self) -> Utf8Bytes
Returns the lowercase equivalent as compact crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::to_lowercase_utf8bytes when retaining heap storage after shrinking is preferred.
See str::to_lowercase.
§Examples
use smol_bytes::StrExt;
assert_eq!("RÜST".to_lowercase_compact_utf8bytes().as_str(), "rüst");Sourcefn to_uppercase_utf8bytes(&self) -> Utf8Bytes
fn to_uppercase_utf8bytes(&self) -> Utf8Bytes
Returns the uppercase equivalent as the default shared Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::to_uppercase_compact_utf8bytes when short results should use inline storage.
See str::to_uppercase.
§Examples
use smol_bytes::StrExt;
assert_eq!("straße".to_uppercase_utf8bytes().as_str(), "STRASSE");Sourcefn to_uppercase_compact_utf8bytes(&self) -> Utf8Bytes
fn to_uppercase_compact_utf8bytes(&self) -> Utf8Bytes
Returns the uppercase equivalent as compact crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::to_uppercase_utf8bytes when retaining heap storage after shrinking is preferred.
See str::to_uppercase.
§Examples
use smol_bytes::StrExt;
assert_eq!("straße".to_uppercase_compact_utf8bytes().as_str(), "STRASSE");Sourcefn to_ascii_lowercase_utf8bytes(&self) -> Utf8Bytes
fn to_ascii_lowercase_utf8bytes(&self) -> Utf8Bytes
Returns the ASCII lowercase equivalent as the default shared Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::to_ascii_lowercase_compact_utf8bytes when short results should use inline
storage.
§Examples
use smol_bytes::StrExt;
assert_eq!("RuSt".to_ascii_lowercase_utf8bytes().as_str(), "rust");Sourcefn to_ascii_lowercase_compact_utf8bytes(&self) -> Utf8Bytes
fn to_ascii_lowercase_compact_utf8bytes(&self) -> Utf8Bytes
Returns the ASCII lowercase equivalent as compact crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::to_ascii_lowercase_utf8bytes when retaining heap storage after shrinking is
preferred.
§Examples
use smol_bytes::StrExt;
assert_eq!("RuSt".to_ascii_lowercase_compact_utf8bytes().as_str(), "rust");Sourcefn to_ascii_uppercase_utf8bytes(&self) -> Utf8Bytes
fn to_ascii_uppercase_utf8bytes(&self) -> Utf8Bytes
Returns the ASCII uppercase equivalent as the default shared Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::to_ascii_uppercase_compact_utf8bytes when short results should use inline
storage.
§Examples
use smol_bytes::StrExt;
assert_eq!("RuSt".to_ascii_uppercase_utf8bytes().as_str(), "RUST");Sourcefn to_ascii_uppercase_compact_utf8bytes(&self) -> Utf8Bytes
fn to_ascii_uppercase_compact_utf8bytes(&self) -> Utf8Bytes
Returns the ASCII uppercase equivalent as compact crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::to_ascii_uppercase_utf8bytes when retaining heap storage after shrinking is
preferred.
§Examples
use smol_bytes::StrExt;
assert_eq!("RuSt".to_ascii_uppercase_compact_utf8bytes().as_str(), "RUST");Sourcefn replace_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes
fn replace_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes
Replaces every match of from with to, returning default shared Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::replace_compact_utf8bytes when short results should use inline storage.
See str::replace.
§Examples
use smol_bytes::StrExt;
assert_eq!("one one".replace_utf8bytes("one", "two").as_str(), "two two");Sourcefn replace_compact_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes
fn replace_compact_utf8bytes(&self, from: &str, to: &str) -> Utf8Bytes
Replaces every match of from with to, returning compact crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::replace_utf8bytes when retaining heap storage after shrinking is preferred.
See str::replace.
§Examples
use smol_bytes::StrExt;
assert_eq!(
"one one".replace_compact_utf8bytes("one", "two").as_str(),
"two two",
);Sourcefn replacen_utf8bytes(&self, from: &str, to: &str, count: usize) -> Utf8Bytes
fn replacen_utf8bytes(&self, from: &str, to: &str, count: usize) -> Utf8Bytes
Replaces at most count matches of from with to, returning default shared
Utf8Bytes.
Shared results retain heap storage when they are later shortened. Use
StrExt::replacen_compact_utf8bytes when short results should use inline storage.
See str::replacen.
§Examples
use smol_bytes::StrExt;
assert_eq!(
"one one".replacen_utf8bytes("one", "two", 1).as_str(),
"two one",
);Sourcefn replacen_compact_utf8bytes(
&self,
from: &str,
to: &str,
count: usize,
) -> Utf8Bytes
fn replacen_compact_utf8bytes( &self, from: &str, to: &str, count: usize, ) -> Utf8Bytes
Replaces at most count matches of from with to, returning compact
crate::compact::Utf8Bytes.
Compact results use inline storage when their contents fit. Use
StrExt::replacen_utf8bytes when retaining heap storage after shrinking is preferred.
See str::replacen.
§Examples
use smol_bytes::StrExt;
assert_eq!(
"one one".replacen_compact_utf8bytes("one", "two", 1).as_str(),
"two one",
);Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".