| Crates.io | credit-facility-rs |
| lib.rs | credit-facility-rs |
| version | 0.1.0 |
| created_at | 2025-08-06 03:49:35.843848+00 |
| updated_at | 2025-08-06 03:49:35.843848+00 |
| description | A rust library for modeling credit facilities with time-aware calculations |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1783356 |
| size | 432,797 |
A Rust library for modeling and managing various types of credit facilities including term loans, revolving credit, open-term loans, and overdraft facilities. Provides deterministic time control for testing and financial calculations.
Multiple facility types
Time control system
Financial calculations
API design
approve, deny, disburse, make_payment, json.set_time(&time).build()use credit_facility_rs::{Money, Rate};
use credit_facility_rs::facilities::TermLoanBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// create a $10,000 personal loan
let mut loan = TermLoanBuilder::new()
.amount(Money::from_major(10_000))
.rate(Rate::from_percentage(8))
.term_months(12)
.build()?;
// approve and disburse
loan.approve()?;
loan.disburse(Money::from_major(10_000))?;
// make a payment
loan.make_payment(Money::from_major(500))?;
// print current state
println!("{}", loan.json());
Ok(())
}
use credit_facility_rs::{Money, Rate, SafeTimeProvider, TimeSource};
use credit_facility_rs::facilities::TermLoanBuilder;
use chrono::{Duration, TimeZone, Utc};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// create controlled time for testing
let time = SafeTimeProvider::new(TimeSource::Test(
Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap()
));
let controller = time.test_control().unwrap();
// create loan with controlled time
let mut loan = TermLoanBuilder::new()
.amount(Money::from_major(100_000))
.rate(Rate::from_percentage(5))
.term_months(36)
.set_time(&time) // set time controller
.build()?;
// originate at t=0
loan.approve()?;
loan.disburse(Money::from_major(100_000))?;
// advance 30 days
controller.advance(Duration::days(30));
// accrue interest and make payment
loan.accrue_interest()?;
loan.process_scheduled_payment()?;
Ok(())
}
All facility types follow consistent patterns:
approve() - approve the facility for usedeny() - deny/cancel the facilitydisburse(amount) - disburse fundsmake_payment(amount) - process a paymentjson() - get JSON representation of current state.set_time(&time) - set time provider during construction.build() - build facility with stored or system timeaccrue_interest() - accrue interest using stored timeupdate_daily_status() - update status using stored time.facility() - access underlying facility data.json() - pretty-printed JSON stateOriginated → Active → Settled/GracePeriod/DelinquentThe examples/ directory contains 11 examples:
Run examples with:
cargo run --example 00_quick_start
cargo run --example 02_time_control
Add to your Cargo.toml:
[dependencies]
credit-facility-rs = "0.1.0"
Dependencies:
rust_decimal - precise decimal arithmeticchrono - date/time handlinghourglass-rs - time control for testinguuid - unique identifiersserde - JSON serializationRun all tests:
cargo test
Runs 88 unit tests covering facility types, interest calculations, payment processing, collateral management, and time manipulation.
The library is organized into modules:
Settled status (no Cancelled status yet)