Crate byte_string [] [src]

The byte_string crate provides two types: ByteStr and ByteString. Both types provide a Debug implementation that outputs the slice using the Rust byte string syntax. ByteStr wraps a byte slice ([u8]). ByteString wraps a vector of bytes (Vec<u8>).

For example:

extern crate byte_string;

use byte_string::ByteStr;

fn main() {
    let s = b"Hello, world!";
    let bs = ByteStr::new(s);
    assert_eq!(format!("{:?}", bs), "b\"Hello, world!\"");
}

ByteStr is an unsized type, as [u8] is. ByteStr::new() returns a &ByteStr and ByteStr::new_mut() returns a &mut ByteStr.

ByteStr and ByteString are meant to be used as an implementation detail. You should generally avoid exposing a ByteStr or a ByteString as part of a struct or enum; prefer exposing the underlying slice or vector instead. However, ByteStr and ByteString implement many traits, including derivable traits, which makes them suitable for use as a private member of a struct or enum.

Structs

ByteStr

Wraps a byte slice and provides a Debug implementation that outputs the slice using the Rust byte string syntax (e.g. b"abc").

ByteString

Wraps a vector of bytes and provides a Debug implementation that outputs the slice using the Rust byte string syntax (e.g. b"abc").