#ascii #debug #string


Wrapper types for outputting byte strings (b”Hello”) using the Debug ({:?}) format

1 stable release

Uses old Rust 2015

1.0.0 Sep 26, 2016

#38 in #ascii

Download history 452/week @ 2021-04-06 426/week @ 2021-04-13 357/week @ 2021-04-20 292/week @ 2021-04-27 385/week @ 2021-05-04 447/week @ 2021-05-11 407/week @ 2021-05-18 358/week @ 2021-05-25 485/week @ 2021-06-01 307/week @ 2021-06-08 292/week @ 2021-06-15 309/week @ 2021-06-22 248/week @ 2021-06-29 619/week @ 2021-07-06 420/week @ 2021-07-13 579/week @ 2021-07-20

1,647 downloads per month
Used in 7 crates (6 directly)


333 lines

byte_string Build Status

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.


byte_string is licensed under the terms of both the MIT license and the Apache License, version 2.0.

No runtime deps