๐ Rust Crate Experiment | byte-repr
A lightweight utility for inspecting and learning about memory representation of integer types in Rust.
๐ Overview
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
โจ Features
- ๐ฆ 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
๐ Usage
Add this to your Cargo.toml
:
[]
= "0.1.0" # update after publishing
Then use in your code:
use represent;
Example Output:
๐ง Supported Types
Currently supports:
i8
u16
u32
u64
u128
usize
โ
impl_byterep!
macro makes it easy to extend support to custom numeric types.
โ ๏ธ Limitations
-
โ 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!
๐งช Tests
Includes integration tests for:
- Endianness checks
- Binary and hex formatting
- Trait conformance per type
- Visual rendering test (smoke check)
๐ฆ License
- Licensed under the MIT License.
See the LICENSE-MIT file for details.
๐ Changelog
See CHANGELOG.md for a history of changes.