10 releases

0.3.0 Dec 17, 2021
0.2.2 Mar 8, 2021
0.2.0 Feb 8, 2021
0.1.5 Feb 6, 2021
0.1.1 Jun 10, 2020
Download history 171/week @ 2022-04-22 279/week @ 2022-04-29 194/week @ 2022-05-06 691/week @ 2022-05-13 579/week @ 2022-05-20 362/week @ 2022-05-27 506/week @ 2022-06-03 353/week @ 2022-06-10 196/week @ 2022-06-17 161/week @ 2022-06-24 161/week @ 2022-07-01 349/week @ 2022-07-08 243/week @ 2022-07-15 300/week @ 2022-07-22 264/week @ 2022-07-29 259/week @ 2022-08-05

1,102 downloads per month
Used in 3 crates (2 directly)

Custom license

14KB
173 lines

Format-bytes

This crate exposes a procedural macro that allows you to format bytestrings. For more background on why you would want to do that, read this article.

Usage

Add this to your Cargo.toml:

[dependencies]
format-bytes = "0.2"

then use the macro like so:

use format_bytes::format_bytes;

fn main() {
    assert_eq!(
        format_bytes!(b"look at those {} bytes", &[0u8, 1, 2]),
        b"look at those \x00\x01\x02 bytes"
    );
}

See more examples of how it works on the documentation of format_bytes! itself.

Missing features

  • Named arguments, but they should be added in a future version
  • Python-like "f-string" functionality is not planned because of its more complex implementation and limited actual benefit
  • format!-like padding helpers: if the need manifests itself, they might appear
  • #[no_std] support

Why not 1.0?

Not until named arguments have landed and the macro gets a bit of mileage (it will be used in Mercurial).

Dependencies

~215–620KB
~15K SLoC