karma-cigarette
karma-cigarette is a small, dependency-free Rust library for recording
interpersonal contributions and turning them into deterministic net
settlements.
The Cocoshiga principle
This crate gives a concrete meaning to 業清算のココシガの理:
Do not replay every act. Preserve the whole, cancel reciprocal karma, and settle only the remainder here and now.
When Alice gives 10 units to Bob, Bob owes Alice 10 units. If Bob later gives 4 units to Alice, only 6 units remain. In a larger group, the same conservation rule produces a compact list of transfers without changing anybody's net position.
This is an application-level accounting model, not financial, legal, or moral advice.
Example
use ;
let mut ledger = new;
ledger.record?;
ledger.record?;
ledger.record?;
let plan = settle?;
assert_eq!;
assert!;
# Ok::
Semantics
- A recorded contribution increases the giver's receivable balance.
- A positive balance means the party should receive units.
- A negative balance means the party should pay units.
- Reciprocal and transitive obligations are netted.
- Settlement order is deterministic because party identifiers are ordered.
- Empty names, self-directed entries, zero-unit entries, and arithmetic overflow are rejected.
License
MIT