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

#798 in Procedural macros

Download history 2526/week @ 2024-04-10 2031/week @ 2024-04-17 2234/week @ 2024-04-24 2284/week @ 2024-05-01 1978/week @ 2024-05-08 1626/week @ 2024-05-15 1456/week @ 2024-05-22 1657/week @ 2024-05-29 2111/week @ 2024-06-05 1971/week @ 2024-06-12 2141/week @ 2024-06-19 1427/week @ 2024-06-26 1196/week @ 2024-07-03 3230/week @ 2024-07-10 2484/week @ 2024-07-17 2685/week @ 2024-07-24

9,748 downloads per month
Used in 52 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.7–1.2MB
~27K SLoC