Module intern

Module intern 

Source
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§

AccountInterner
A specialized interner for account names.
AsDecimal
Wrapper to serialize Decimal as fixed 16-byte binary with rkyv. This is more compact and faster than string serialization.
AsInternedStr
Wrapper to serialize InternedStr as String with rkyv. Use with #[rkyv(with = AsInternedStr)] on InternedStr fields.
AsNaiveDate
Wrapper to serialize NaiveDate as i32 (days from Common Era) with rkyv. This is 4 bytes instead of 10+ for string, and faster to serialize.
CurrencyInterner
A specialized interner for currency codes.
InternedStr
An interned string reference.
StringInterner
A string interner that deduplicates strings.
SyncStringInterner
Thread-safe string interner using a mutex.

Type Aliases§

AsOptionInternedStr
Type alias for rkyv wrapper for Option<InternedStr>. Use: #[rkyv(with = rkyv::with::Map<AsInternedStr>)]
AsVecInternedStr
Type alias for rkyv wrapper for Vec<InternedStr>. Use: #[rkyv(with = rkyv::with::Map<AsInternedStr>)]