Skip to main content

ValidationSession

Struct ValidationSession 

Source
pub struct ValidationSession<P: SessionPhase = Pending> { /* private fields */ }
Expand description

Stateful two-phase validation harness for callers (like the loader) that need to interleave validation with other pipeline steps.

The session’s phase is tracked at the type level via P: SessionPhase (see the phase module for the marker types and the rationale). The standard sequence is:

  1. ValidationSession::new returns ValidationSession<Pending>.
  2. run_early consumes Pending and returns (ValidationSession<EarlyDone>, Vec<ValidationError>).
  3. Booking (and the post-booking plugin pass) runs externally on the directive list.
  4. run_late consumes EarlyDone and returns (ValidationSession<LateDone>, Vec<ValidationError>).
  5. finalize consumes LateDone and returns the deferred E2003 unused-pad warnings.

Standalone callers that don’t run booking between phases (LSP, FFI, tests) run all four 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.

§Spanned vs. unspanned

Each transition has a _spanned variant (run_early_spanned, run_late_spanned) for &[Spanned<Directive>] input. The spanned variants preserve source-location info on emitted errors so callers (LSP, loader, FFI) can render file:line:column diagnostics directly.

§Migration from pre-#1236

Replace:

let mut session = ValidationSession::new(options);
let mut errors = session.run_phase(&directives, Phase::Early, today);
errors.extend(session.run_phase(&directives, Phase::Late, today));
errors.extend(session.finalize());

with:

let session = ValidationSession::new(options);
let (session, mut errors) = session.run_early(&directives, today);
let (session, late_errors) = session.run_late(&directives, today);
errors.extend(late_errors);
errors.extend(session.finalize());

The compile-time enforcement replaces the pre-#1236 runtime debug_assert! + release-mode no-op for phase ordering.

§Example

use rustledger_validate::{ValidationOptions, ValidationSession};
use rustledger_core::{Directive, naive_date};

let directives: Vec<Directive> = vec![];
let today = naive_date(2030, 1, 1).unwrap();

let session = ValidationSession::new(ValidationOptions::default());
let (session, mut errors) = session.run_early(&directives, today);
// ... booking runs here; plugins ran BEFORE Early ...
let (session, late_errors) = session.run_late(&directives, today);
errors.extend(late_errors);
errors.extend(session.finalize());

Implementations§

Source§

impl ValidationSession<Pending>

Source

pub fn new(options: ValidationOptions) -> Self

Create a new session with the given validation options. The returned session is bound to the Pending marker; the only legal next step is run_early (or its spanned variant).

Source

pub fn run_early( self, directives: &[Directive], today: NaiveDate, ) -> (ValidationSession<EarlyDone>, Vec<ValidationError>)

Run Phase::Early over a slice of raw Directives.

Early runs account/structural checks that don’t need filled-in amounts. The session’s internal LedgerState is updated so run_late sees the accumulated state (open accounts, commodities, pending pads).

Consumes the session and returns it bound to EarlyDone alongside the errors collected during the phase. The new phase marker prevents a second run_early call at compile time.

Source

pub fn run_early_spanned( self, directives: &[Spanned<Directive>], today: NaiveDate, ) -> (ValidationSession<EarlyDone>, Vec<ValidationError>)

Variant of run_early for Spanned<Directive> slices. Preserves source-location info on emitted errors.

Source§

impl ValidationSession<EarlyDone>

Source

pub fn run_late( self, directives: &[Directive], today: NaiveDate, ) -> (ValidationSession<LateDone>, Vec<ValidationError>)

Run Phase::Late over a slice of raw Directives.

Late runs balance/inventory/currency checks that need filled-in amounts. Must be called AFTER booking has run on the directive list (and after the post-booking plugin pass, if any).

Consumes the session and returns it bound to LateDone alongside the errors collected during the phase. The new phase marker prevents a second run_late call at compile time.

Source

pub fn run_late_spanned( self, directives: &[Spanned<Directive>], today: NaiveDate, ) -> (ValidationSession<LateDone>, Vec<ValidationError>)

Variant of run_late for Spanned<Directive> slices. Preserves source-location info on emitted errors.

Source§

impl ValidationSession<LateDone>

Source

pub fn finalize(self) -> Vec<ValidationError>

Flush deferred end-of-validation checks. Currently emits unused pad warnings (E2003). Consumes the session because deferred state is per-session.

Auto Trait Implementations§

§

impl<P> Freeze for ValidationSession<P>

§

impl<P> RefUnwindSafe for ValidationSession<P>
where P: RefUnwindSafe,

§

impl<P> Send for ValidationSession<P>
where P: Send,

§

impl<P> Sync for ValidationSession<P>
where P: Sync,

§

impl<P> Unpin for ValidationSession<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for ValidationSession<P>

§

impl<P> UnwindSafe for ValidationSession<P>
where P: UnwindSafe,

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