StringLike

Trait StringLike 

Source
pub trait StringLike<S>: Sized{
    // Required methods
    fn as_ref_type(&self) -> &S;
    fn as_bytes(&self) -> &[u8] ;
    fn into_owned_type(self) -> <S as ToOwned>::Owned
       where <S as ToOwned>::Owned: From<Box<S>>;
    fn to_owned_type(&self) -> <S as ToOwned>::Owned;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn len(&self) -> usize { ... }
    fn as_str(&self) -> &str
       where S: AsRef<str> { ... }
    fn into_string(self) -> String
       where <S as ToOwned>::Owned: Into<String> + From<Box<S>> { ... }
    fn to_string(&self) -> String
       where <S as ToOwned>::Owned: Into<String> { ... }
}
Expand description

Trait for string types that provide various operations

Required Methods§

Source

fn as_ref_type(&self) -> &S

Borrow a string reference as &S

Source

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

Borrow the string as bytes

Source

fn into_owned_type(self) -> <S as ToOwned>::Owned
where <S as ToOwned>::Owned: From<Box<S>>,

Consume a string and convert it to an owned string. S::to_owned is called on Borrowed/Inlined/RefCounted variants. Boxed variants are converted directly into S::Owned (most likely without copy or allocation).

Source

fn to_owned_type(&self) -> <S as ToOwned>::Owned

Convert a string reference to an owned string. S::to_owned is called on all variants.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if this is an empty string

Source

fn len(&self) -> usize

Returns the length of this string in bytes

Source

fn as_str(&self) -> &str
where S: AsRef<str>,

Borrow the string as an &str

Source

fn into_string(self) -> String
where <S as ToOwned>::Owned: Into<String> + From<Box<S>>,

Consume a string and convert it to a String

Source

fn to_string(&self) -> String
where <S as ToOwned>::Owned: Into<String>,

Convert a string reference to a String

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§