deki-rs
A personal Rust utility crate — helper types, traits, macros, and re-exports that reduce boilerplate.
Quick Start
[]
= { = "0.4", = ["random", "lerp"] }
use Lerpable;
let val: f32 = 0.0.lerp; // 5.0
Features
| Feature | Default | What it adds |
|---|---|---|
random |
✅ | fastrand re-exports, f32r(), Vec::random() |
approx |
✅ | Fast bit-hack math via DekiExtApprox — sqrt_fast, exp_fast, pow_fast, log2_fast |
lerp |
✅ | Linear / gated / cyclic / step interpolation traits and methods |
derive_more |
✅ | Full derive_more re-export (Debug, Clone, PartialEq, etc.) |
proc |
— | Proc-macro support (string→ident, token stream helpers) |
deki_core — Runtime Utilities
Core Types
StackMap<K, V> — Insertion-Ordered Key-Value Map
Preserves insertion order and allows duplicate keys. Keys stored in a Vec — linear search.
let mut map: = Defaultdefault;
*map.entry = 42;
assert_eq!;
for in map.iter // insertion order
Syncable — 'static + Send + Sync in One Word
DefaultClear — Reset Any Default Type
Adds .clear() to any Default type (resets to Self::default()).
let mut state = default;
state.clear; // resets to MyState::default()
Aliases
| Name | Is |
|---|---|
Ghost |
PhantomData |
Str |
&'static str |
New |
derive_new::new |
ext |
extension_traits::extension |
Plus re-exports of buns, type_cell, and maflow.
Math
Approximate Math (approx feature)
Fast bit-hack math (~1% error, bit-hack based):
use DekiExtApprox;
let x = 1.5f32;
x.exp_fast; // ~1% error, 2.2× faster than std
x.pow_fast; // ~1% error, 1.5× faster than std
x.log2_fast; // ~1% error
x.sqrt_fast; // ~0.1% error, 1.4× faster than std
Interpolation (lerp feature)
Linear Interpolation
use Lerpable;
let val: f32 = 0.0.lerp; // 5.0
// For integers (uses mul_f32 rounding)
use LerpableF32;
let val: i32 = 0i32.lerp; // 30
Gated Lerp — Snap When Close
use Glerpable;
let mut val = 0.0f32;
let arrived = val.glerp; // snaps when within 0.5 of target
Cyclic Lerp — Auto-Choose Shortest Direction
use Clerpable;
let val: f32 = 0.0.lerp_qucy;
// Result: 0.99 (not 0.09) — picks the shorter path
// Gated cyclic variant
let mut val = 0.99f32;
let arrived = val.glerp_qucy; // snapped
Step Interpolation
use Stepable;
let mut val = 0.0f32;
let arrived = val.sterp; // moves 2.0 per call, true when arrived
Cyclic Step Interpolation
use CycleStapable;
let mut val = 0.0f32;
let arrived = val.sterp_qucy; // cyclic, moves 0.1 per call
Easing
let t = 0.5f32;
let eased = t.smooth; // smoothstep: t*t*(3-2*t)
Cycling Math
add_qucy / sub_qucy — Modular Arithmetic
Fast modular arithmetic (assumes current value is in range):
// Circular buffer: advance index, wrap to 0 at capacity
let idx: usize = 99usize.add_qucy; // 0
// Move backwards through a 10-slot inventory, wrapping to the end
let slot: i32 = 2i32.sub_qucy; // 9
mul_f32 — Multiply Integer by f32 (rounded)
let count: i32 = 5.mul_f32; // 13 (rounded)
#[derive(Cycle)] — Auto-Cycling Enums
Generates cycle_next() and cycle_prev() for unit-variant enums:
use Cycle;
let mut dir = North;
dir = dir.cycle_next; // East
dir = dir.cycle_prev; // North
Randomness (random feature)
use *;
let val: f32 = f32r;
let my_vec = vec!;
let random_item = my_vec.random; // picks a random element
Helper Macros
qonst! — Named Constants
Creates a pub const named after the type, without requiring Default:
qonst!;
// => pub const VEC3: Vec3 = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
qonst!;
// => pub const DIRECTION: Direction = Direction::North;
trait_alias! — Trait Aliases
trait_alias!;
// => pub trait MyTrait: Clone + Send + Sync {}
// => impl<C: Clone + Send + Sync> MyTrait for C {}
default! — Shorthand Default
default!;
// => impl Default for MyStruct { fn default() -> Self { Self { a: 0, b: Default::default() } } }
deki_macros — Proc Macros
Derive Macros
#[derive(Cycle)]
Generates cycle_next() and cycle_prev() for unit-variant enums.
#[derive(ForceDefault)]
Generates Default by calling .default() on each field:
// => Default produces Config { timeout: 0, name: String::default() }
#[derive(EnumFieldCount)]
Generates fn field_count(&self) -> usize for enums:
use EnumFieldCount;
assert_eq!;
assert_eq!;
assert_eq!;
Procedural Macros
xoxo! — Bool Pattern Matching
xoxo!
quimp! — Quick Trait Implementation
For traits with a single required method:
quimp!
match_fns! — Declarative Enum Methods
match_fns!
derive_from! — Generate From Impl
Generate impl From<A> for B from function signatures:
;
derive_from!
let w: Wrapper = .into;
assert_eq!;
derive_math! — Generate Arithmetic Impl
Generate impl Add/Sub/Mul/Div<A> for T from function signatures:
derive_math!
let a = Vec2 ;
let b = Vec2 ;
assert!;
foname! — Name Mangling
Converts identifiers to different cases:
foname! // my_function_name
foname! // myFunctionName
foname! // MY_FUNCTION_NAME
foname! // myfunctionname
foname! // MYFUNCTIONNAME
Attribute Macros
#[imp(...)] — Attach Methods to Types or Impl Blocks
Function-level syntax:
Foreign types (auto-generates a trait):
// Generates: trait StringTrimAllExt { fn trim_all(&self) -> Self; }
// and impls it for String
Impl block syntax:
// Auto-generates: StringAutoMethodExt
#[derived(...)] — Batch Apply Derives
Batch-apply derive macros by name:
use derived;
// => #[derive(PartialEq, Eq, Hash, Clone, Copy)]
License
Dual licensed under MIT or Apache-2.0.