Trait Bytes

Source
pub trait Bytes: Debug {
    // Required method
    fn as_byte_slice(&self) -> &[u8] ;

    // Provided method
    fn bytes_as_os_str(&self) -> &OsStr { ... }
}
Expand description

Conversion Trait implemented for many byte sources that can be used as arguments for search patterns and replacement strings. The methods probably shouldn’t be called anywhere outside this crate.

Required Methods§

Source

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

Returns the underlying buffer as a &[u8] slice.

§WARNING

Windows support requires transmuting the OsStr into a slice and back, since there is no other way to directly access the underlying bytes. This should be fine for what this library does, since all inputs are valid UTF8/WTF8 anyway and all this library does is combine or split bytes at valid edges. One exception is the possibility to supply arbitrarily prepared slices as inputs, but even then, all strings are checked for validity before being transmuted back into OsStr so there is no chance to end up with a broken string.

Provided Methods§

Source

fn bytes_as_os_str(&self) -> &OsStr

Don’t use this outside of this crate.

§WARNING

Transmutes arbitrary byte slices into OsStr on Windows which could cause bad things to happen. To prevent this, the strings are checked for validity before the conversion and if they contain invalid bytes a panic will ensure.

§Panics

On Windows this can panic when called on a malformed collection of bytes.

Implementations on Foreign Types§

Source§

impl Bytes for &&OsStr

Source§

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

Source§

impl Bytes for &str

Source§

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

Source§

impl Bytes for &Vec<u8>

Source§

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

Source§

impl Bytes for &OsStr

Source§

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

Source§

impl Bytes for &OsString

Source§

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

Source§

impl Bytes for &[u8]

Source§

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

Source§

impl Bytes for str

Source§

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

Source§

impl Bytes for Vec<u8>

Source§

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

Source§

impl Bytes for OsStr

Source§

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

Source§

impl Bytes for OsString

Source§

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

Implementors§