Crates.io | include-bytes-plus |
lib.rs | include-bytes-plus |
version | 1.1.0 |
source | src |
created_at | 2022-02-03 05:38:38.170535 |
updated_at | 2023-09-22 11:27:53.246885 |
description | Improved include_bytes! allowing to reinterpret input differently |
homepage | |
repository | https://github.com/DoumanAsh/include-bytes-plus |
max_upload_size | |
id | 526052 |
size | 41,571 |
Improved version of Rust's include_bytes
macro that allows to reinterpret input as differently typed array.
Due to inability to capture current file path in the stable Rust, this macro only accepts paths relative to crate's root.
Primitive fixed sized unsigned integers with optional endianness suffix;
Arrays with unsigned integers;
use include_bytes_plus::include_bytes;
let bytes = include_bytes!("tests/include.in");
let bytes_u16 = include_bytes!("tests/include.in" as u16);
let bytes_u16_2 = include_bytes!("tests/include with whitespaces.in" as u16);
let bytes_u16_3 = include_bytes!("tests/include with whitespaces.in" as [u8; 48]);
let bytes_u16_4 = include_bytes!("tests/include with whitespaces.in" as [u16; 12]);
let bytes_u16be = include_bytes!("tests/include.in" as u16be);
assert_eq!(bytes.len(), bytes_u16.len() * 2);
assert_eq!(bytes.len(), bytes_u16.len() * 2);
assert_eq!(bytes.len(), bytes_u16_2.len() * 2);
assert_eq!(bytes_u16_3.len(), 1);
assert_eq!(bytes_u16_3[0].len(), 48);
assert_eq!(bytes_u16_4.len(), 2);
assert_eq!(bytes_u16_4[0].len(), 12);
assert_eq!(bytes_u16_4[1].len(), 12);
assert_eq!(bytes_u16be.len(), bytes_u16.len());
Set env variable RUST_INCLUDE_BYTES_LOG=1
to enable logging of each parsed file statistics