# Malakoi
[](https://crates.io/crates/malakoi)
[](https://docs.rs/malakoi)
[](https://github.com/pas2rust/malakoi/blob/main/LICENSE)






---
Malakoi is a **Rust crate for advanced procedural macros and utility components**, designed to enhance productivity and ergonomics in Rust development. It focuses on **math helpers, macro-driven workflows, and code generation** for repetitive patterns.
## Features
- `Math` derive for numeric structs:
- Generate `approach_*` methods to smoothly move numeric fields toward a target with a max delta.
- `Builder` integrations (via `kenzu::Builder`) for ergonomic initialization.
- Easy integration with structs of **any numeric type** (`usize`, `i32`, `f64`, etc.).
- Fully tested examples and doc-tests for reliable usage.
- Zero dependencies outside standard Rust ecosystem + optional feature helpers.
## Installation
Add Malakoi to your `Cargo.toml`:
```bash
cargo add malakoi
```
```rust
use kenzu::Builder;
use malakoi::Math;
#[derive(Debug, Builder, Math, Clone, Default)]
pub struct CalcStruct {
pub usize: usize,
pub u8: u8,
pub u16: u16,
pub u32: u32,
pub u64: u64,
pub u128: u128,
pub isize: isize,
pub i16: i16,
pub i32: i32,
pub i64: i64,
pub i128: i128,
pub f64: f64,
pub f32: f32,
}
#[test]
fn approach_usize() {
let mut calc_struct = CalcStruct::new().usize::<usize>(10).build().unwrap();
calc_struct.approach_usize(20, 6);
assert_eq!(calc_struct.usize, 16);
calc_struct.approach_usize(20, 6);
assert_eq!(calc_struct.usize, 20);
}
#[test]
fn discount_usize() {
let mut calc_struct = CalcStruct::new()
.usize::<usize>(10)
.build()
.unwrap();
calc_struct.discount_usize(20);
assert_eq!(calc_struct.usize, 8);
}
#[test]
fn div_usize() {
let mut calc_struct = CalcStruct::new()
.usize::<usize>(10)
.build()
.unwrap();
calc_struct.div_usize(5);
assert_eq!(calc_struct.usize, 2);
}
#[test]
fn inflate_usize() {
let mut calc_struct = CalcStruct::new()
.usize::<usize>(10)
.build()
.unwrap();
calc_struct.inflate_usize(20);
assert_eq!(calc_struct.usize, 12);
}
#[test]
fn mul_usize() {
let mut calc_struct = CalcStruct::new()
.usize::<usize>(1)
.build()
.unwrap();
calc_struct.mul_usize(5);
assert_eq!(calc_struct.usize, 5);
}
#[test]
fn sub_usize() {
let mut calc_struct = CalcStruct::new()
.usize::<usize>(6)
.build()
.unwrap();
calc_struct.sub_usize(5);
assert_eq!(calc_struct.usize, 1);
}
#[test]
fn sum_usize() {
let mut calc_struct = CalcStruct::new().usize::<usize>(1).build().unwrap();
calc_struct.sum_usize(5);
assert_eq!(calc_struct.usize, 6);
}
```
# ❤️ Donate
[](https://github.com/pas2rust/pas2rust/blob/main/pas-monero-donate.png)
[](https://github.com/pas2rust/pas2rust/blob/main/pas-bitcoin-donate.png)