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

#229 in Procedural macros

Download history 4472/week @ 2025-10-13 4786/week @ 2025-10-20 3841/week @ 2025-10-27 5434/week @ 2025-11-03 6348/week @ 2025-11-10 4522/week @ 2025-11-17 4650/week @ 2025-11-24 6455/week @ 2025-12-01 6082/week @ 2025-12-08 5554/week @ 2025-12-15 1339/week @ 2025-12-22 1429/week @ 2025-12-29 3141/week @ 2026-01-05 3320/week @ 2026-01-12 4606/week @ 2026-01-19 4966/week @ 2026-01-26

16,153 downloads per month
Used in 14 crates (11 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

~1.5MB
~39K SLoC