#string #debugging #byte #ascii #hello #byte-slice #format

byte_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

#1445 in Text processing

Download history 11808/week @ 2024-03-14 13813/week @ 2024-03-21 9881/week @ 2024-03-28 10640/week @ 2024-04-04 11686/week @ 2024-04-11 9802/week @ 2024-04-18 9842/week @ 2024-04-25 9650/week @ 2024-05-02 9639/week @ 2024-05-09 10531/week @ 2024-05-16 9736/week @ 2024-05-23 8925/week @ 2024-05-30 8944/week @ 2024-06-06 10140/week @ 2024-06-13 10123/week @ 2024-06-20 6870/week @ 2024-06-27

37,548 downloads per month
Used in 12 crates (9 directly)

MIT/Apache

15KB
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.

License

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

No runtime deps