pub struct ValidationSession { /* private fields */ }Expand description
Stateful two-phase validation harness for callers (like the loader) that need to interleave validation with other pipeline steps.
Typical use: run run_phase with Phase::Early
AFTER plugins but BEFORE booking, then Phase::Late AFTER booking.
Call finalize at the end to flush deferred checks
(e.g., unused pads).
Standalone callers that don’t run booking between phases (e.g. LSP, FFI, tests) run the three calls back-to-back against the same directive list. The verbosity is intentional — it surfaces the phase split so callers explicitly choose whether to interleave booking between Early and Late.
§Migration from pre-#1116
The free-function shortcuts validate, validate_with_options,
validate_with_today, validate_spanned_with_options, and
validate_spanned_with_today were removed. Replace each call site
with the three-step ValidationSession sequence shown below.
§Preconditions
Each session is single-use:
- Call
Phase::Earlyat most once. - Call
Phase::Lateat most once, and only AFTEREarly. - Call
finalizeat most once, and only AFTER both phases.
In debug builds, violating this contract panics. In release builds
the duplicate / out-of-order call is a no-op that returns an empty
error list — this is deliberate so a buggy caller can’t silently
corrupt the shared LedgerState (inventories are additive, so a
second Late pass would double-book every transaction).
§Example
use rustledger_validate::{Phase, ValidationOptions, ValidationSession};
use rustledger_core::{Directive, naive_date};
let directives: Vec<Directive> = vec![];
let today = naive_date(2030, 1, 1).unwrap();
let mut session = ValidationSession::new(ValidationOptions::default());
let mut errors = session.run_phase(&directives, Phase::Early, today);
// ... booking runs here; plugins ran BEFORE Early ...
errors.extend(session.run_phase(&directives, Phase::Late, today));
errors.extend(session.finalize());Implementations§
Source§impl ValidationSession
impl ValidationSession
Sourcepub fn new(options: ValidationOptions) -> Self
pub fn new(options: ValidationOptions) -> Self
Create a new session with the given validation options.
Sourcepub fn run_phase(
&mut self,
directives: &[Directive],
phase: Phase,
today: NaiveDate,
) -> Vec<ValidationError>
pub fn run_phase( &mut self, directives: &[Directive], phase: Phase, today: NaiveDate, ) -> Vec<ValidationError>
Run one validation phase over a slice of raw Directives.
Early runs account/structural checks that don’t need
filled-in amounts. Late runs balance/inventory/currency
checks that do. The session’s internal LedgerState is updated
by each phase so subsequent calls see the accumulated state.
§Panics (debug only)
Panics in debug builds if called out of order — Phase::Late
before Phase::Early, or either phase invoked twice. In release
builds the offending call is a no-op returning an empty Vec.
See the type-level “Preconditions” section.
Sourcepub fn run_phase_spanned(
&mut self,
directives: &[Spanned<Directive>],
phase: Phase,
today: NaiveDate,
) -> Vec<ValidationError>
pub fn run_phase_spanned( &mut self, directives: &[Spanned<Directive>], phase: Phase, today: NaiveDate, ) -> Vec<ValidationError>
Sourcepub fn finalize(self) -> Vec<ValidationError>
pub fn finalize(self) -> Vec<ValidationError>
Flush deferred end-of-validation checks. Currently emits unused
pad warnings (E2003). Call once after both phases have run —
dropping the returned Vec discards those warnings.
Consumes the session because deferred state is per-session;
re-running finalize on the same state would re-emit the same
errors.
Auto Trait Implementations§
impl Freeze for ValidationSession
impl RefUnwindSafe for ValidationSession
impl Send for ValidationSession
impl Sync for ValidationSession
impl Unpin for ValidationSession
impl UnsafeUnpin for ValidationSession
impl UnwindSafe for ValidationSession
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.