A Rust workspace for experimenting with binary operations, bit manipulation, and low-level data representations.
This project is organized as a Rust workspace with the following structure:
binary-playground/
├── Cargo.toml # Workspace configuration
├── cli/ # CLI application crate
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
└── experiments/ # Library crate containing all experiments
├── Cargo.toml
└── src/
└── lib.rs
cargo buildcargo run --bin binary-playground listcargo run --bin binary-playground run <experiment-name> [args...]Experiments with bit manipulation operations like AND, OR, XOR, NOT, and bit shifting.
Examples:
# Show binary representation and bit statistics
cargo run --bin binary-playground run bit-ops 42
# Perform XOR operation
cargo run --bin binary-playground run bit-ops 42 xor 15
# Bit shifting
cargo run --bin binary-playground run bit-ops 8 shift-left 2
# Bitwise AND
cargo run --bin binary-playground run bit-ops 255 and 15Experiments with binary arithmetic operations and number representations.
Examples:
# Show different representations of a number
cargo run --bin binary-playground run binary-math -42
# Perform arithmetic with overflow detection
cargo run --bin binary-playground run binary-math 255 add 1
cargo run --bin binary-playground run binary-math 100 mul 200Experiments with byte arrays, endianness, and data serialization.
Examples:
# Convert number to little-endian bytes
cargo run --bin binary-playground run bytes 1234 le
# Convert number to big-endian bytes
cargo run --bin binary-playground run bytes 1234 be
# Interpret byte sequence as number
cargo run --bin binary-playground run bytes bytes 210,4,0,0To add a new experiment, follow these steps:
pub mod my_experiment {
use super::*;
pub struct MyExperiment;
impl Experiment for MyExperiment {
fn name(&self) -> &'static str {
"my-experiment"
}
fn description(&self) -> &'static str {
"Description of what this experiment does"
}
fn usage(&self) -> &'static str {
"<arg1> [arg2] [optional-flag]"
}
fn run(&self, args: &[String]) -> Result<()> {
// Your experiment implementation here
println!("Running my experiment with args: {:?}", args);
Ok(())
}
}
}impl ExperimentRegistry {
pub fn new() -> Self {
let mut registry = Self {
experiments: HashMap::new(),
};
// Register all available experiments
registry.register(Box::new(bit_operations::BitOperationsExperiment));
registry.register(Box::new(binary_arithmetic::BinaryArithmeticExperiment));
registry.register(Box::new(byte_manipulation::ByteManipulationExperiment));
registry.register(Box::new(my_experiment::MyExperiment)); // Add this line
registry
}
}cargo build
cargo run --bin binary-playground list
cargo run --bin binary-playground run my-experiment# Quick iteration during development
cargo run --bin binary-playground run <experiment> [args]
# Build and run optimized version
cargo build --release
./target/release/binary-playground run <experiment> [args]Add dependencies to the appropriate crate:
- For CLI-specific dependencies: Edit
cli/Cargo.toml - For experiment dependencies: Edit
experiments/Cargo.toml - For workspace-wide dependencies: Edit the root
Cargo.tomlworkspace section
# Run all tests
cargo test
# Run tests for a specific crate
cargo test -p experiments
cargo test -p binary-playground-cliThis project follows Rust best practices for workspace organization:
- Separation of Concerns: CLI logic is separate from experiment implementations
- Trait-based Extensibility: All experiments implement the
Experimenttrait - Registry Pattern: Experiments are automatically discoverable through the registry
- Workspace Dependencies: Shared dependencies are managed at the workspace level
- Library-first Design: Core functionality is in a library crate, CLI is just a thin wrapper
The Experiment trait provides a standard interface that makes it easy to:
- Add new experiments without modifying existing code
- Automatically generate help text and usage information
- Maintain consistent error handling across all experiments
- Enable easy testing of individual experiments
When adding new experiments:
- Follow the existing code style and patterns
- Include comprehensive usage examples in your experiment's help text
- Handle errors gracefully using
anyhow::Result - Add tests for your experiment logic
- Update this README with examples of your new experiment