StringLike

Trait StringLike 

Source
pub trait StringLike<S>: Sized{
Show 20 methods // 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 as_os_str(&self) -> &OsStr where S: AsRef<OsStr> { ... } fn as_path(&self) -> &Path where S: AsRef<Path> { ... } fn as_c_str(&self) -> &CStr where S: AsRef<CStr> { ... } fn into_string(self) -> String where <S as ToOwned>::Owned: Into<String> + From<Box<S>> { ... } fn into_os_string(self) -> OsString where <S as ToOwned>::Owned: Into<OsString> + From<Box<S>> { ... } fn into_path_buf(self) -> PathBuf where <S as ToOwned>::Owned: Into<PathBuf> + From<Box<S>> { ... } fn into_c_string(self) -> CString where <S as ToOwned>::Owned: Into<CString> + From<Box<S>> { ... } fn into_vec_bytes(self) -> Vec<u8> where <S as ToOwned>::Owned: Into<Vec<u8>> + From<Box<S>> { ... } fn to_string(&self) -> String where <S as ToOwned>::Owned: Into<String> { ... } fn to_os_string(&self) -> OsString where <S as ToOwned>::Owned: Into<OsString> { ... } fn to_path_buf(&self) -> PathBuf where <S as ToOwned>::Owned: Into<PathBuf> { ... } fn to_c_string(&self) -> CString where <S as ToOwned>::Owned: Into<CString> { ... } fn to_vec_bytes(&self) -> Vec<u8> where <S as ToOwned>::Owned: Into<Vec<u8>> { ... }
}
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 as_os_str(&self) -> &OsStr
where S: AsRef<OsStr>,

Available on crate features std and osstr only.

Borrow the string as an &OsStr

Source

fn as_path(&self) -> &Path
where S: AsRef<Path>,

Available on crate features std and path only.

Borrow the string as a &Path

Source

fn as_c_str(&self) -> &CStr
where S: AsRef<CStr>,

Available on crate feature cstr only.

Borrow the string as a &CStr

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 into_os_string(self) -> OsString
where <S as ToOwned>::Owned: Into<OsString> + From<Box<S>>,

Available on crate features std and osstr only.

Consume a string and convert it to an OsString

Source

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

Available on crate features std and path only.

Consume a string and convert it to a PathBuf

Source

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

Available on crate feature cstr only.

Consume a string and convert it to a CString

Source

fn into_vec_bytes(self) -> Vec<u8>
where <S as ToOwned>::Owned: Into<Vec<u8>> + From<Box<S>>,

Available on crate feature bytes only.

Consume a string and convert it to a Vec<u8>

Source

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

Convert a string reference to a String

Source

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

Available on crate features std and osstr only.

Convert a string reference to an OsString

Source

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

Available on crate features std and path only.

Convert a string reference to a PathBuf

Source

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

Available on crate feature cstr only.

Convert a string reference to a CString

Source

fn to_vec_bytes(&self) -> Vec<u8>
where <S as ToOwned>::Owned: Into<Vec<u8>>,

Available on crate feature bytes only.

Convert a string reference to a Vec<u8>

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§