Trait StringType

Source
pub trait StringType: Sealed + Into<String> {
    // Required methods
    fn as_bytes(&self) -> &[u8];
    fn is_allocated(&self) -> bool;
    fn is_empty(&self) -> bool;
    fn len(&self) -> usize;
}
Available on crate feature alloc only.
Expand description

Trait for standard utf-8 string types. Implemented for &str, String, Box<str> and Cow<'_, str>

Required Methods§

Source

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

Get the string as bytes

Source

fn is_allocated(&self) -> bool

Check if the string is allocated

Source

fn is_empty(&self) -> bool

Check if the string is empty

Source

fn len(&self) -> usize

Get the length of the 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.

Implementations on Foreign Types§

Source§

impl StringType for &str

Source§

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

Source§

fn is_allocated(&self) -> bool

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

impl StringType for Cow<'_, str>

Source§

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

Source§

fn is_allocated(&self) -> bool

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

impl StringType for Box<str>

Source§

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

Source§

fn is_allocated(&self) -> bool

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

impl StringType for String

Source§

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

Source§

fn is_allocated(&self) -> bool

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Implementors§