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>
impl<'a> StaticSessionExceptions<'a>
Sourcepub const fn new(
source: CalendarSource,
first_covered: NaiveDate,
last_covered: NaiveDate,
records: &'a [SessionExceptionRecord<'a>],
) -> Result<Self, StaticSessionExceptionsError>
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.
Sourcepub const fn source(self) -> CalendarSource
pub const fn source(self) -> CalendarSource
Returns the identity these records are scoped to.
Sourcepub const fn coverage(self) -> ExceptionCoverage
pub const fn coverage(self) -> ExceptionCoverage
Returns the audited trade-date window.
Sourcepub fn record_on(
self,
trade_date: NaiveDate,
) -> Option<SessionExceptionRecord<'a>>
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.
Sourcepub fn exception_on(self, trade_date: NaiveDate) -> DateException<'a>
pub fn exception_on(self, trade_date: NaiveDate) -> DateException<'a>
Returns what this table knows about trade_date.
Sourcepub const fn records(self) -> &'a [SessionExceptionRecord<'a>]
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>
impl<'a> Clone for StaticSessionExceptions<'a>
impl<'a> Copy for StaticSessionExceptions<'a>
Source§impl<'a> Debug for StaticSessionExceptions<'a>
impl<'a> Debug for StaticSessionExceptions<'a>
impl<'a> Eq for StaticSessionExceptions<'a>
Source§impl<'a> PartialEq for StaticSessionExceptions<'a>
impl<'a> PartialEq for StaticSessionExceptions<'a>
Source§impl SessionExceptionSource for StaticSessionExceptions<'_>
impl SessionExceptionSource for StaticSessionExceptions<'_>
Source§fn may_affect(&self, first: NaiveDate, last: NaiveDate) -> bool
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
fn source(&self) -> CalendarSource
Source§fn coverage(&self) -> Option<ExceptionCoverage>
fn coverage(&self) -> Option<ExceptionCoverage>
None when nothing is audited. Read moreSource§fn exception_on(&self, trade_date: NaiveDate) -> DateException<'_>
fn exception_on(&self, trade_date: NaiveDate) -> DateException<'_>
trade_date. Read more