Expand description
String interning for accounts and currencies.
String interning reduces memory usage by storing each unique string once and using references to that single copy. This is especially useful for account names and currencies which appear repeatedly throughout a ledger.
§Example
use rustledger_core::intern::StringInterner;
let mut interner = StringInterner::new();
let s1 = interner.intern("Expenses:Food");
let s2 = interner.intern("Expenses:Food");
let s3 = interner.intern("Assets:Bank");
// s1 and s2 point to the same string
assert!(std::ptr::eq(s1.as_str().as_ptr(), s2.as_str().as_ptr()));
// s3 is different
assert!(!std::ptr::eq(s1.as_str().as_ptr(), s3.as_str().as_ptr()));Structs§
- Account
Interner - A specialized interner for account names.
- AsDecimal
- Wrapper to serialize
Decimalas fixed 16-byte binary with rkyv. This is more compact and faster than string serialization. - AsInterned
Str - Wrapper to serialize
InternedStras String with rkyv. Use with#[rkyv(with = AsInternedStr)]onInternedStrfields. - AsNaive
Date - Wrapper to serialize
NaiveDateas i32 (days from Common Era) with rkyv. This is 4 bytes instead of 10+ for string, and faster to serialize. - Currency
Interner - A specialized interner for currency codes.
- Interned
Str - An interned string reference.
- String
Interner - A string interner that deduplicates strings.
- Sync
String Interner - Thread-safe string interner using a mutex.
Type Aliases§
- AsOption
Interned Str - Type alias for rkyv wrapper for
Option<InternedStr>. Use:#[rkyv(with = rkyv::with::Map<AsInternedStr>)] - AsVec
Interned Str - Type alias for rkyv wrapper for
Vec<InternedStr>. Use:#[rkyv(with = rkyv::with::Map<AsInternedStr>)]