Skip to main content

ValidationSession

Struct ValidationSession 

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

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

Source

pub fn new(options: ValidationOptions) -> Self

Create a new session with the given validation options.

Source

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.

Source

pub fn run_phase_spanned( &mut self, directives: &[Spanned<Directive>], phase: Phase, today: NaiveDate, ) -> Vec<ValidationError>

Variant of run_phase for Spanned<Directive> slices. Preserves source-location info on emitted errors so callers (LSP, loader, FFI) can render file:line:column diagnostics directly.

Same phase-ordering preconditions as run_phase.

Source

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§

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.