███████╗ █████╗ ██╗ ██╗ █████╗ ████████╗
╚══███╔╝██╔══██╗██║ ██╔╝██╔══██╗╚══██╔══╝
███╔╝ ███████║█████╔╝ ███████║ ██║
███╔╝ ██╔══██║██╔═██╗ ██╔══██║ ██║
███████╗██║ ██║██║ ██╗██║ ██║ ██║
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
Zakat
Rust library for Islamic Zakat calculation. Uses rust_decimal for precision.
Features
- Gold, Silver, Business, Agriculture, Livestock, Mining & Rikaz
- Stocks, Mutual Funds, Crypto (as liquid assets)
- Professional Income (Gross/Net)
- Zakat Fitrah
- Configurable Nisab thresholds
- Portfolio aggregation (Dam' al-Amwal)
- Asset Labeling (e.g., "Main Store", "Crypto Wallet")
- Input Sanitization & Validation (Rejects negative values, ensures safe configuration)
- Flexible Configuration (Env Vars, JSON, Fluent API)
- Fiqh Compliance (Jewelry exemptions, Madhab-specific rules, Hawl requirements)
- Async Support (Optional integration with
tokioandasync-trait) - Live Pricing Interface (e.g. for API integration)
- Detailed Reporting (Livestock in-kind details, calculation traces, metadata support)
- [NEW]
explain()Debugging (Get human-readable trace of calculations)
Install
With Async Support (Default):
[]
= "0.5"
= "1.39"
= { = "1", = ["full"] } # Required if using async features
Synchronous Only (Lighter weight):
[]
= { = "0.5", = false }
= "1.39"
Usage
Business Zakat
Note: v0.5 uses a new Fluent API. No more Builders! You can pass standard Rust types (
i32,f64,&str) directly.
use *;
Advanced Usage (Complex Scenarios)
For complex scenarios involving debts and receivables:
let assets = new
.cash
.inventory
.receivables
.liabilities
.debt // Deductible immediate debt
.label
.hawl;
Portfolio Management
Handles multiple assets with "Dam' al-Amwal" (Wealth Aggregation) logic.
use *;
use PortfolioStatus;
Async & Live Pricing (Optional)
Enable the async feature to use these capabilities.
use *;
use ;
;
async
Configuration
Flexible and safe configuration options.
use *;
// Load from Environment Variables (ZAKAT_GOLD_PRICE, etc.)
let config = from_env?;
// Or load from JSON
let config = try_from_json?;
// Or using Fluent API
let config = new
.with_gold_price
.with_silver_price
.with_madhab;
Advanced Assets (Jewelry & Livestock)
use *;
// Personal Jewelry (Exempt in Shafi/Maliki, Payable in Hanafi)
let necklace = new
.weight
.metal_type
.usage
.label;
// Livestock Reporting
let prices = new
.sheep_price
.cow_price
.camel_price;
let camels = new
.count
.animal_type
.prices;
let result = camels.calculate_zakat?;
if result.is_payable
Modules
| Module | Nisab |
|---|---|
maal::precious_metals |
85g Gold / 595g Silver |
maal::business |
85g Gold |
maal::income |
85g Gold |
maal::investments |
85g Gold |
maal::agriculture |
653 kg |
maal::livestock |
Count-based |
maal::mining |
Rikaz: None / Mines: 85g Gold |
fitrah |
N/A |
Migrating from v0.4 (Builder Pattern)
v0.5 removes all *Builder structs. Migration is straightforward:
- let assets = BusinessZakatBuilder::default()
- .cash_on_hand(10_000)
- .build()?;
+ let assets = BusinessZakat::new()
+ .cash(10_000);
Key changes:
::builder()→::new()(now infallible, returnsSelf).build()?→ removed, object is ready immediately- Validation errors now occur at
.calculate_zakat()instead of.build() - Errors include Asset Labels for better debugging
Contributing
- Add tests
- Use
rust_decimal - If adding async features, ensure they are gated behind
#[cfg(feature = "async")] - Run
cargo testandcargo check --no-default-features
Support
"Those who spend their wealth in the cause of Allah..." — Al-Baqarah 2:262
License
MIT