Skip to main content

LedgerStore

Struct LedgerStore 

Source
pub struct LedgerStore { /* private fields */ }
Expand description

F-046’s optional local ledger: appends/reads/garbage-collects redacted LedgerRecord metadata at a JSONL file path (see the module doc for the .db-named-but-JSONL decision).

Implementations§

Source§

impl LedgerStore

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Source

pub fn default_path() -> PathBuf

$XDG_DATA_HOME/tokenfold/ledger.db, falling back to <home>/.local/share/tokenfold/ledger.db — mirrors retrieval_store::default_store_path’s HOME/USERPROFILE fallback.

Source

pub fn path(&self) -> &Path

Source

pub fn append(&self, record: &LedgerRecord) -> Result<(), TokenFoldError>

Source

pub fn read_all(&self) -> Result<Vec<LedgerRecord>, TokenFoldError>

Reads every well-formed record. A line that fails to parse (e.g. a partial write left by a crash mid-append) is skipped rather than failing the whole read. A missing file reads as an empty ledger, not an error (an analytics-enabled run before any record exists yet is the common case, not a failure).

Source

pub fn gc(&self, retention_days: u64) -> Result<LedgerGcOutcome, TokenFoldError>

Rewrites the ledger file keeping only records whose timestamp is within retention_days of now; records with an unparsable timestamp are kept (fail safe rather than silently discarding data this can’t confidently date). Survivors keep their original relative order — nothing about a kept record is touched or reordered.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.