[][src]Trait osstrtools::Bytes

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

    fn bytes_as_os_str(&self) -> &OsStr { ... }
}

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

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.

Loading content...

Provided methods

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.

Loading content...

Implementations on Foreign Types

impl<'_> Bytes for &'_ [u8][src]

impl Bytes for Vec<u8>[src]

impl<'_> Bytes for &'_ Vec<u8>[src]

impl Bytes for OsStr[src]

impl<'_> Bytes for &'_ OsStr[src]

impl<'_, '_> Bytes for &'_ &'_ OsStr[src]

impl Bytes for OsString[src]

impl<'_> Bytes for &'_ OsString[src]

impl Bytes for str[src]

impl<'_> Bytes for &'_ str[src]

Loading content...

Implementors

Loading content...