Trait StringBehavior

Source
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§

Source

fn as_bytes(&self) -> &[u8]

Gets the byte representation of the string.

§Examples
let s = StringB::from("hello");
let bytes = s.as_bytes();
Source

fn as_str(&self) -> &str

Gets the string slice representation of the value.

§Examples
let s = StringB::from("hello");
let slice = s.as_str();
Source

fn extract(&self) -> String

Source

fn as_string(&self) -> String

Converts the value to a String.

§Examples
let s = StringB::from("hello");
let string = s.as_string();
Source

fn to_uppercase(&self) -> Self

Converts the string to uppercase.

§Examples
let s = StringB::from("hello");
assert_eq!(s.to_uppercase().as_str(), "HELLO");
Source

fn to_lowercase(&self) -> Self

Converts the string to lowercase.

§Examples
let s = StringB::from("HELLO");
assert_eq!(s.to_lowercase().as_str(), "hello");
Source

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");
Source

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");
Source

fn concat<T>(&self, other: T) -> Self
where T: AsRef<str>,

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");
Source

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.

Implementors§