5 releases

0.0.5 May 2, 2023
0.0.4 Sep 20, 2022
0.0.3 Aug 31, 2022
0.0.2 Aug 29, 2022
0.0.1 Aug 29, 2022

#1382 in Procedural macros

Download history 1775/week @ 2024-11-15 1905/week @ 2024-11-22 3189/week @ 2024-11-29 3099/week @ 2024-12-06 3532/week @ 2024-12-13 1357/week @ 2024-12-20 537/week @ 2024-12-27 1713/week @ 2025-01-03 2211/week @ 2025-01-10 2912/week @ 2025-01-17 2217/week @ 2025-01-24 1931/week @ 2025-01-31 2596/week @ 2025-02-07 2253/week @ 2025-02-14 2806/week @ 2025-02-21 2662/week @ 2025-02-28

10,649 downloads per month
Used in 70 crates (3 directly)

Apache-2.0

20KB
293 lines

bytes-lit

Creates byte arrays from literal values.

Currently supports integer literals of unbounded size.

Example

Get a byte array given an integer value. Leading zeros in hex (0x) and binary (0b) integer form are preserved.

let bytes = bytes!(0x00ed3f55dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
assert_eq!(bytes, [
    0, 237, 63, 85, 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114,
    250, 111, 250, 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
]);

Get the minimum sized byte array given an integer value to capture the value. Leading zeros are ignored.

let bytes = bytesmin!(0x00ed3f55dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
assert_eq!(bytes, [
    237, 63, 85, 222, 196, 114, 80, 165, 42, 140, 11, 183, 3, 142, 114,
    250, 111, 250, 174, 51, 86, 47, 119, 205, 43, 98, 158, 247, 253, 66, 77,
]);

lib.rs:

Bytes converts literals into an array of bytes.

Currently supports only integer literals of unbounded size.

Dependencies

~0.6–1.1MB
~25K SLoC