debtsolver

Crates.iodebtsolver
lib.rsdebtsolver
version0.2.0
sourcesrc
created_at2019-11-19 21:12:22.338613
updated_at2019-12-12 10:40:13.05278
descriptionTrack and settle debts between parties with the fewest transactions.
homepage
repositoryhttps://github.com/varunsrin/debtsolver
max_upload_size
id182539
size22,285
Varun Srinivasan (varunsrin)

documentation

https://docs.rs/debtsolver

README

Debtsolver

Track and settle debts between parties with the fewest transactions.

Example

use debtsolver::Ledger;
use debtsolver::Transaction;
use debtsolver::transaction;

fn main() {
    let mut ledger = Ledger::new();

    // Let's say that:
    // Alice paid 20 for Bob's lunch
    // Bob paid 20 for Charlie's dinner the next day.
    ledger.add_transaction(transaction!("Alice", "Bob", (20, "USD")));
    ledger.add_transaction(transaction!("Bob", "Charlie", (20, "USD")));

    for payment in ledger.settle() {
        println!("{}", payment)
    } 
    // Debtsolver will resolve this with one payment:
    // Alice owes Charlie 20.00 USD


    // Now lets say that:
    //   Bob paid for Alice's breakfast (20).
    //   Charlie paid for Bob's lunch (50).
    //   Alice paid for Charlie's dinner (35).
    ledger.add_transaction(transaction!("Alice", "Bob", (20, "USD")));
    ledger.add_transaction(transaction!("Bob", "Charlie", (50, "USD")));
    ledger.add_transaction(transaction!("Charlie", "Alice", (35, "USD")));
    

    for payment in ledger.settle() {
        println!("{}", payment)
    } 
    // Debtsolver will resolve this with just two payments:
    // Bob owes Alice 15.00 USD
    // Bob owes Charlie 15.00 USD
}
Commit count: 10

cargo fmt