Trait Str

Source
pub unsafe trait Str {
    const CONTAINS_NUL: bool;

    // Required methods
    unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self;
    fn as_bytes(&self) -> &[u8] ;
}
Expand description

Represents str-like types that could be cast to valid byte patterns and back.

§Safety

It is the implementor’s responsibility to ensure that the bytes returned by as_bytes could be safely passed to from_bytes_unchecked.

Required Associated Constants§

Source

const CONTAINS_NUL: bool

Indicates whether the bytes returned by as_bytes contain a NUL byte.

Required Methods§

Source

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Casts the given bytes to a reference to Self.

§Safety

The bytes must be valid byte patterns for Self.

Source

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

Casts the given reference to Self to a slice of bytes.

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 Str for str

Source§

const CONTAINS_NUL: bool = false

Source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Source§

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

Source§

impl Str for CStr

Source§

const CONTAINS_NUL: bool = true

Source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Source§

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

Source§

impl Str for OsStr

Source§

const CONTAINS_NUL: bool = false

Source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Source§

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

Source§

impl Str for Path

Source§

const CONTAINS_NUL: bool = false

Source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Source§

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

Source§

impl Str for [u8]

Source§

const CONTAINS_NUL: bool = false

Source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Source§

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

Implementors§