bytes_lit

Macro bytesmin

Source
bytesmin!() { /* proc-macro */ }
Expand description

Bytesmin converts literals into an array of bytes of minimal size to capture the value.

Currently supports only integer literals of unbounded size.

Leading zeroes on integer literals are discarded and not preserved. The generated byte slice is the minimal bytes required to capture the literal provided.

To preserve leading zeros, use bytes!.

ยงExamples

let bytes = bytes_lit::bytesmin!(1);
assert_eq!(bytes, [1]);
let bytes = bytes_lit::bytesmin!(9);
assert_eq!(bytes, [9]);
let bytes = bytes_lit::bytesmin!(0xfded3f55dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
assert_eq!(bytes, [
    253, 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,
]);
let bytes = bytes_lit::bytesmin!(0x00000000dec47250a52a8c0bb7038e72fa6ffaae33562f77cd2b629ef7fd424d);
assert_eq!(bytes, [
    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,
]);