Skip to main content

StaticSessionExceptions

Struct StaticSessionExceptions 

Source
pub struct StaticSessionExceptions<'a> { /* private fields */ }
Expand description

An allocation-free SessionExceptionSource over caller-owned records.

Records are keyed by venue-local trade date and are exact dates, never inferred weekday or holiday rules. Construction validates the whole slice once; queries then use exact-date binary search without allocation, I/O, or clock reads.

The table stores no operator data of its own. It carries the caller’s identity scope and audited window so the engine can refuse a provider built for another schedule and so an unaudited date stays distinguishable from an ordinary weekday.

§Example

use chrono::NaiveDate;
use exchange_hours::{
    CalendarSource, DateException, Exchange, ExceptionBlock, SessionExceptionRecord,
    SessionExceptionSource, StaticSessionExceptions,
};

let day = |d| NaiveDate::from_ymd_opt(2011, 11, d).ok_or("invalid date");

// A regular-only early close: extended trading continues past 13:00 local.
static BLOCKS: [ExceptionBlock; 2] = [
    ExceptionBlock::regular(0, 9 * 3_600 + 30 * 60, 13 * 3_600),
    ExceptionBlock::extended(0, 13 * 3_600, 17 * 3_600),
];
let records = [SessionExceptionRecord::replace_sessions(day(25)?, &BLOCKS)];
let table = StaticSessionExceptions::new(
    CalendarSource::Exchange(Exchange::Nasdaq),
    day(21)?,
    day(28)?,
    &records,
)?;

assert_eq!(table.exception_on(day(25)?), DateException::ReplaceSessions(&BLOCKS));
assert_eq!(table.exception_on(day(24)?), DateException::KnownNormal);
assert_eq!(table.exception_on(day(29)?), DateException::OutOfCoverage);

Implementations§

Source§

impl<'a> StaticSessionExceptions<'a>

Source

pub const fn new( source: CalendarSource, first_covered: NaiveDate, last_covered: NaiveDate, records: &'a [SessionExceptionRecord<'a>], ) -> Result<Self, StaticSessionExceptionsError>

Validates and borrows a slice of trade-date records for one identity.

first_covered and last_covered publish the audited window: dates inside it with no record are DateException::KnownNormal, and dates outside it are DateException::OutOfCoverage. An empty record slice is valid and asserts that the whole window was audited and found normal. This is a const fn, so a caller can validate while constructing a constant or static table.

Validation scans left to right, checking the coverage bounds, then each record’s ordering and window membership, then each replacement block’s ordering and domain, and returns the first violation.

§Errors

Returns StaticSessionExceptionsError for inverted coverage bounds, the first duplicate or out-of-order record date, the first record outside the coverage window, an empty replacement set, or the first replacement block that is out of order, carries an offset outside ExceptionBlock::MIN_DAY_OFFSET..=ExceptionBlock::MAX_DAY_OFFSET, opens outside 0..86_400, or closes outside 0..=86_400.

Source

pub const fn source(self) -> CalendarSource

Returns the identity these records are scoped to.

Source

pub const fn coverage(self) -> ExceptionCoverage

Returns the audited trade-date window.

Source

pub fn record_on( self, trade_date: NaiveDate, ) -> Option<SessionExceptionRecord<'a>>

Returns the exact record for trade_date, if one exists.

Lookup is allocation-free and logarithmic in the number of records. A date outside the coverage window still returns its record if one was supplied, which validation makes impossible.

Source

pub fn exception_on(self, trade_date: NaiveDate) -> DateException<'a>

Returns what this table knows about trade_date.

Source

pub const fn records(self) -> &'a [SessionExceptionRecord<'a>]

Returns the validated records in their strictly increasing order.

Trait Implementations§

Source§

impl<'a> Clone for StaticSessionExceptions<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for StaticSessionExceptions<'a>

Source§

impl<'a> Debug for StaticSessionExceptions<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for StaticSessionExceptions<'a>

Source§

impl<'a> PartialEq for StaticSessionExceptions<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl SessionExceptionSource for StaticSessionExceptions<'_>

Source§

fn may_affect(&self, first: NaiveDate, last: NaiveDate) -> bool

One partition point over the validated, sorted records — the same shape the built-in table’s gate answers from. A provider that audited a window and recorded nothing (an empty slice) answers false for every window, which is what makes it a true no-op on the engine’s hot path (issue #127): the engine must not derive a trading day — and refuse on a day that derivation reaches — for a provider that can move nothing.

Source§

fn source(&self) -> CalendarSource

Returns the single schedule identity these records describe.
Source§

fn coverage(&self) -> Option<ExceptionCoverage>

Returns the audited trade-date window, or None when nothing is audited. Read more
Source§

fn exception_on(&self, trade_date: NaiveDate) -> DateException<'_>

Returns what this provider knows about trade_date. Read more
Source§

impl<'a> StructuralPartialEq for StaticSessionExceptions<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.