https://github.com/stellar/bytes-lit
Creates byte arrays from literal values.
https://github.com/stellar/bytes-lit
Last synced: about 1 year ago
JSON representation
Creates byte arrays from literal values.
- Host: GitHub
- URL: https://github.com/stellar/bytes-lit
- Owner: stellar
- License: apache-2.0
- Created: 2022-08-29T18:25:48.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T05:19:07.000Z (almost 2 years ago)
- Last Synced: 2025-03-22T18:41:14.062Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 9
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```rust
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.
```rust
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,
]);
```