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

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

#1562 in Text processing

Download history 10124/week @ 2024-09-29 9083/week @ 2024-10-06 9506/week @ 2024-10-13 12556/week @ 2024-10-20 10818/week @ 2024-10-27 10178/week @ 2024-11-03 12002/week @ 2024-11-10 13098/week @ 2024-11-17 13023/week @ 2024-11-24 11657/week @ 2024-12-01 13902/week @ 2024-12-08 14917/week @ 2024-12-15 8400/week @ 2024-12-22 10262/week @ 2024-12-29 11821/week @ 2025-01-05 10617/week @ 2025-01-12

42,403 downloads per month
Used in 13 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