| Crates.io | zfuel |
| lib.rs | zfuel |
| version | 0.3.1 |
| created_at | 2024-12-10 09:45:19.18051+00 |
| updated_at | 2025-06-27 13:39:57.390137+00 |
| description | ZFuel types used for a mutual credit accounting system |
| homepage | https://github.com/zo-el/zfuel |
| repository | |
| max_upload_size | |
| id | 1478289 |
| size | 81,864 |
A high-precision Rust library for handling ZFuel types in mutual credit accounting systems. ZFuel provides fixed-point arithmetic with 6 decimal places of precision, ensuring accurate financial calculations without floating-point rounding errors.
Add to your Cargo.toml:
[dependencies]
zfuel = "0.2.2"
use zfuel::{ZFuel, Fraction};
// Create a ZFuel amount
let amount = ZFuel::from_str("123.456789").unwrap();
// Perform arithmetic operations
let doubled = (amount + amount).unwrap();
let half = (amount * Fraction::new(1, 2).unwrap()).unwrap();
// Calculate fees (1%)
let fee = (amount * Fraction::new(1, 100).unwrap()).unwrap();
// Format as string
println!("Amount: {}", amount); // "123.456789"
println!("Doubled: {}", doubled); // "246.913578"
println!("Half: {}", half); // "61.728394"
println!("Fee: {}", fee); // "1.234567"
# Install nightly toolchain
rustup install nightly
# Install cargo-fuzz
cargo install cargo-fuzz
The project includes comprehensive test coverage:
# Run all tests (unit tests and fuzz tests)
make all
# Run only unit tests
make test
# Run only fuzz tests
make fuzz
# Run specific fuzz tests
make fuzz-fuzz_fuel
make fuzz-fuzz_fraction
make fuzz-fuzz_fuel_string
make fuzz-fuzz_fuel_operations
make fuzz-fuzz_fraction_operations
make fuzz-fuzz_fee_calculations
make fuzz-fuzz_fuel_serialization
The project includes several fuzz tests to ensure robustness:
fuzz_fuel: Basic ZFuel creation and validationfuzz_fraction: Fraction operations and validationfuzz_fuel_string: String parsing and validationfuzz_fuel_operations: Arithmetic operationsfuzz_fraction_operations: Fraction arithmeticfuzz_fee_calculations: Fee computationfuzz_fuel_serialization: Serialization/deserializationContributions are welcome! Please see our Contributing Guidelines for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.