Expand description
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.1"
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
§Why not 1.0?
Not until named arguments have landed and the macro gets a bit of mileage (it will be used in Mercurial).
Macros§
- format_
bytes - Creates a
Vec<u8>
using interpolation of runtime expressions. - write_
bytes - Like
format_bytes!
, but writes to a stream given as an additional first argument.
Structs§
- Utf8
- Adaptor for types that implement
std::fmt::Display
. The Unicode output is encoded as UTF-8.
Traits§
- Display
Bytes - Let types decide how to format themselves for presentation to users in a byte-stream output.
Functions§
- join
- Format a sequence of values with the given separator repeated between any two consecutive values, but not at the start or end of the sequence.