Skip to main content

FakeLedger

Struct FakeLedger 

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

In-memory ledger for local mode execution.

Initialized with a balance derived from nanny.toml → limits.max_cost_units. Every debit reduces the balance. When balance hits zero, the policy stops execution via BudgetExhausted.

No persistence. No network. No real money. The receipts are real records — they just don’t move actual funds.

Implementations§

Source§

impl FakeLedger

Source

pub fn new(initial_balance: u64) -> Self

Create a new FakeLedger with the given initial balance.

Pass limits.max_cost_units from your nanny.toml here. That makes the budget limit and the ledger balance consistent.

Trait Implementations§

Source§

impl Ledger for FakeLedger

Source§

fn authorize(&self, amount: u64) -> LedgerDecision

Check whether a spend is possible without committing to it.

Called by the executor to build PolicyContext. Does not change the balance.

Source§

fn debit(&mut self, amount: u64) -> Result<Receipt, LedgerError>

Spend amount units and return a receipt.

Reduces the balance permanently. Returns an error if the balance is insufficient.

Source§

fn balance(&self) -> u64

Current unspent balance.

Source§

fn total_debited(&self) -> u64

Total units spent across all debits.

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, 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.