pub trait StringBehavior {
// Required methods
fn as_bytes(&self) -> &[u8] ⓘ;
fn as_str(&self) -> &str;
fn extract(&self) -> String;
fn as_string(&self) -> String;
fn to_uppercase(&self) -> Self;
fn to_lowercase(&self) -> Self;
fn trim(&self) -> Self;
fn replace(&self, from: &str, to: &str) -> Self;
fn concat<T>(&self, other: T) -> Self
where T: AsRef<str>;
fn from_utf8(value: Vec<u8>) -> Self;
}Required Methods§
Sourcefn as_bytes(&self) -> &[u8] ⓘ
fn as_bytes(&self) -> &[u8] ⓘ
Gets the byte representation of the string.
§Examples
let s = StringB::from("hello");
let bytes = s.as_bytes();Sourcefn as_str(&self) -> &str
fn as_str(&self) -> &str
Gets the string slice representation of the value.
§Examples
let s = StringB::from("hello");
let slice = s.as_str();fn extract(&self) -> String
Sourcefn as_string(&self) -> String
fn as_string(&self) -> String
Converts the value to a String.
§Examples
let s = StringB::from("hello");
let string = s.as_string();Sourcefn to_uppercase(&self) -> Self
fn to_uppercase(&self) -> Self
Converts the string to uppercase.
§Examples
let s = StringB::from("hello");
assert_eq!(s.to_uppercase().as_str(), "HELLO");Sourcefn to_lowercase(&self) -> Self
fn to_lowercase(&self) -> Self
Converts the string to lowercase.
§Examples
let s = StringB::from("HELLO");
assert_eq!(s.to_lowercase().as_str(), "hello");Sourcefn trim(&self) -> Self
fn trim(&self) -> Self
Removes whitespace at the beginning and end of the string.
§Examples
let s = StringB::from(" hello ");
assert_eq!(s.trim().as_str(), "hello");Sourcefn replace(&self, from: &str, to: &str) -> Self
fn replace(&self, from: &str, to: &str) -> Self
Replaces all occurrences of ‘from’ with ‘to’.
§Examples
let s = StringB::from("hello world");
assert_eq!(s.replace("world", "planet").as_str(), "hello planet");Sourcefn concat<T>(&self, other: T) -> Self
fn concat<T>(&self, other: T) -> Self
Concatenates the current string with another string or &str.
§Examples
let s1 = StringB::from("hello");
let s2 = " world";
assert_eq!(s1.concat(s2).as_str(), "hello world");fn from_utf8(value: Vec<u8>) -> Self
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.