A lightweight utility for inspecting and learning about memory representation of integer types in Rust.
byte-repr
is a simple, extensible Rust crate to help visualize how numeric types are represented in memory. It supports both little-endian and big-endian byte formats, binary representation, and hex with zero-padding.
Useful for:
- 🧠 Learning & teaching endianness and bit-level encoding
- 🛠️ Debugging binary data
- 🧬 Understanding low-level memory layouts in Rust
- 📦 Print values in:
- Binary format (grouped bits)
- Little-endian byte array
- Big-endian byte array
- Hexadecimal representation (zero-padded)
- 🧩 Macro-based extensibility for custom numeric types
- 🧪 Tested against all supported integer types
- 🎨 Color-coded output for clarity
Add this to your Cargo.toml
:
[dependencies]
byte-repr = "0.1.0" # update after publishing
Then use in your code:
use byte_repr::represent;
fn main() {
let x = 42u16;
represent(&x);
}
Currently supports:
i8
u16
u32
u64
u128
usize
✅ impl_byterep!
macro makes it easy to extend support to custom numeric types.
-
❌ Not yet #![no_std] compatible
-
❌ No support for wasm32 (WebAssembly) targets
-
📌 Relies on println! for display, which isn't available in no_std or wasm
✅ These will be addressed in upcoming versions. Stay tuned!
Includes integration tests for:
- Endianness checks
- Binary and hex formatting
- Trait conformance per type
- Visual rendering test (smoke check)
- Licensed under the MIT License.
See the LICENSE-MIT file for details.
See CHANGELOG.md for a history of changes.
Made with ❤️ by Himangshu Pan