Skip to main content

FilamentStore

Trait FilamentStore 

Source
pub trait FilamentStore: Send + Sync {
Show 13 methods // Required methods fn register_spool( &self, spool: NewSpool, source: EventSource, actor: Actor, reason: String, ) -> BoxFuture<'_, Result<(SpoolRecord, EventRecord), StoreError>>; fn apply_spool_changes( &self, changes: Vec<SpoolMutation>, charges: Vec<Charge>, pends: Vec<Pend>, ) -> BoxFuture<'_, Result<SpoolWrite, StoreError>>; fn settle_print( &self, print_id: PrintId, outcome: PrintOutcome, ended: EventDraft, charges: Vec<Charge>, pends: Vec<Pend>, marks: Vec<SpoolMutation>, ) -> BoxFuture<'_, Result<Settlement, StoreError>>; fn print_settlement( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Option<(Timestamp, PrintOutcome)>, StoreError>>; fn charges( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Vec<ChargeRecord>, StoreError>>; fn pending_charges( &self, tool: Option<i64>, ) -> BoxFuture<'_, Result<Vec<PendingCharge>, StoreError>>; fn spool( &self, id: SpoolId, ) -> BoxFuture<'_, Result<Option<SpoolRecord>, StoreError>>; fn spools( &self, include_retired: bool, ) -> BoxFuture<'_, Result<Vec<SpoolRecord>, StoreError>>; fn loaded_spools( &self, ) -> BoxFuture<'_, Result<Vec<SpoolRecord>, StoreError>>; fn record_file_position( &self, print_id: PrintId, position: FilePosition, ) -> BoxFuture<'_, Result<(), StoreError>>; fn file_position( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Option<FilePosition>, StoreError>>; fn file_tallies(&self) -> BoxFuture<'_, Result<Vec<FileTally>, StoreError>>; fn account_tallies( &self, tallies: Vec<FileTally>, charges: Vec<Charge>, marks: Vec<SpoolMutation>, events: Vec<EventDraft>, ) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>;
}
Expand description

The filament ledger: spools, the charges against them, the charges held for a spool not yet named, each print’s settlement and last file position, and the printer’s per-file print tallies.

§Every write is one transaction

Each writing method writes everything it was given and every event that goes with it, or — when any part is refused — none of it: a crash or a refusal halfway leaves the ledger as it was before the call.

§A charge is debited exactly once

A charge is keyed by its ChargeKey, stored under ChargeKey::canonical. Wherever a charge is submitted — apply_spool_changes, settle_print or account_tallies — the same rules hold:

  • A charge whose key is not yet recorded subtracts its charged grams from its spool — a retired spool included, since retirement refuses later commands rather than the settlement of earlier prints, and below zero included, since a charge is never refused or clamped — records the charge, and appends its event. The spool’s updated_at becomes the later of its own and the charge’s instant. A charge naming no spool subtracts nothing and is still recorded.
  • A charge whose key is already recorded is a replay: it subtracts nothing and appends no event.
  • A charge whose key is pending takes it: the pending charge is removed in the same transaction that records the charge, so it is debited once.

A pend is held the same way: one whose key is already pending or already charged is a replay and writes nothing; otherwise it is held and its event appended.

Within one call, the charges are applied first, in the order given, then the pends, then the mutations — so a correction sets its figure after any pending charge the same command took.

§A spool change, and what refuses one

A mutation applies its SpoolChange, sets the spool’s updated_at to its instant, and appends the event the change carries — a clear_marks carries none, and a mark_unverified the spool already holds is a no-op that appends nothing. The trust functions are the contract’s, SpoolTrust::marked and SpoolTrust::cleared, and no implementation restates them. Every refusal is the whole call’s:

  • StoreError::NotFound for a spool that does not exist.
  • StoreError::ConstraintRefused naming spools.loaded_on_tool for a load onto a tool another unretired spool holds. A swap is two mutations in one call, the unload and then the load.
  • StoreError::ConstraintRefused naming spools.retired_at for a load, an unload, a set_remaining, a clear_marks or a retire of a retired spool. A mark_unverified still applies to one, because a settlement marks the spool that fed the print whatever has happened to it since.

Every method is asynchronous, the trait is dyn-compatible, and it is shareable across threads, because its consumers hold it behind Arc<dyn FilamentStore>.

Required Methods§

Source

fn register_spool( &self, spool: NewSpool, source: EventSource, actor: Actor, reason: String, ) -> BoxFuture<'_, Result<(SpoolRecord, EventRecord), StoreError>>

Register a spool, minting its identifier.

In one transaction, writes the spool and a spool_registered event — with no print, from source, received at the spool’s registered_at — whose payload carries the record as written, actor and reason.

§Errors

Refuses a spool registered loaded onto a tool another unretired spool holds with StoreError::ConstraintRefused naming spools.loaded_on_tool.

Source

fn apply_spool_changes( &self, changes: Vec<SpoolMutation>, charges: Vec<Charge>, pends: Vec<Pend>, ) -> BoxFuture<'_, Result<SpoolWrite, StoreError>>

Apply spool mutations, charges and pends, with their events, in one transaction — all of them or none.

§Errors

Refuses the whole call as the trait’s own documentation states.

Source

fn settle_print( &self, print_id: PrintId, outcome: PrintOutcome, ended: EventDraft, charges: Vec<Charge>, pends: Vec<Pend>, marks: Vec<SpoolMutation>, ) -> BoxFuture<'_, Result<Settlement, StoreError>>

Settle a print, once.

In one transaction: the print’s remaining charges and its pends, under the replay rules, with their events; the mark_unverified mutations in marks, applied by the rules every mutation is, with their events; the ended event, which is the print’s print_ended; and the print’s settlement, at that event’s instant, with outcome. A print already settled is answered Settlement::AlreadySettled and nothing is written.

It does not end the print record: the domain calls PrintStore::end_print after it, so a crash between the two leaves a settled, open print that the next close-out only ends.

§Errors

Refuses a print that does not exist with StoreError::NotFound, and otherwise as the trait’s own documentation states.

Source

fn print_settlement( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Option<(Timestamp, PrintOutcome)>, StoreError>>

When a print was settled, and with which outcome, when it has been.

Source

fn charges( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Vec<ChargeRecord>, StoreError>>

Every charge recorded against a print, by tool and then by segment.

This is how a later segment is charged only the remainder after a restart.

Source

fn pending_charges( &self, tool: Option<i64>, ) -> BoxFuture<'_, Result<Vec<PendingCharge>, StoreError>>

Every charge still pending — on one tool, when one is named — oldest first.

Source

fn spool( &self, id: SpoolId, ) -> BoxFuture<'_, Result<Option<SpoolRecord>, StoreError>>

Read one spool.

Source

fn spools( &self, include_retired: bool, ) -> BoxFuture<'_, Result<Vec<SpoolRecord>, StoreError>>

Read every spool — retired ones only when asked for — most recently registered first.

Source

fn loaded_spools(&self) -> BoxFuture<'_, Result<Vec<SpoolRecord>, StoreError>>

Read every unretired spool loaded on a tool, by tool.

Source

fn record_file_position( &self, print_id: PrintId, position: FilePosition, ) -> BoxFuture<'_, Result<(), StoreError>>

Record how far into its file a print had got.

Keeps the latest by observed_at: a position observed before the one held is not recorded.

§Errors

Refuses a print that does not exist with StoreError::NotFound.

Source

fn file_position( &self, print_id: PrintId, ) -> BoxFuture<'_, Result<Option<FilePosition>, StoreError>>

The latest file position recorded for a print.

Source

fn file_tallies(&self) -> BoxFuture<'_, Result<Vec<FileTally>, StoreError>>

Every file’s tally as last accounted, by file name and then origin.

Source

fn account_tallies( &self, tallies: Vec<FileTally>, charges: Vec<Charge>, marks: Vec<SpoolMutation>, events: Vec<EventDraft>, ) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>

Account the prints the printer’s tallies counted and this system never saw, in one transaction.

Their charges, under the replay rules; their mark_unverified mutations, applied by the rules every mutation is; their unaccounted_print and file_tally_rebaselined events; and the advanced tallies, each stored by file name and origin over whatever was held — so a crash leaves either none of it or all of it. Answers every event it appended, in the order it appended them.

§Errors

Refuses a tally whose generation is below the one held for its file with StoreError::ConstraintRefused naming file_tallies.generation, and otherwise as the trait’s own documentation states.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§