#[non_exhaustive]pub enum TimeSpec {
Range(Range),
Period {
start: DateTime<Utc>,
end: DateTime<Utc>,
},
}Expand description
Time specification for historical data requests.
This enum ensures that only one time specification method is used at a time, making range-vs-period exclusivity unrepresentable at compile time.
Direct enum construction can still build a Period whose start >= end.
Use TimeSpec::period or TimeSpec::validate when constructing or
accepting a standalone TimeSpec. HistoryRequestBuilder::build and
TimeSpec deserialization also perform this validation.
Serializes as explicitly tagged JSON:
{ "kind": "range", "range": "6mo" } or
{ "kind": "period", "start": 1716595200000, "end": 1719187200000 }.
Period timestamps use Unix milliseconds.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Range(Range)
Use a logical range preset (e.g., “1 month”, “1 year”).
Period
Use an explicit time period with start and end timestamps.
Implementations§
Source§impl TimeSpec
impl TimeSpec
Sourcepub fn period(
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<TimeSpec, MarketError>
pub fn period( start: DateTime<Utc>, end: DateTime<Utc>, ) -> Result<TimeSpec, MarketError>
Build a validated explicit period time specification.
§Errors
Returns MarketError::InvalidPeriod when start >= end.
Sourcepub fn validate(&self) -> Result<(), MarketError>
pub fn validate(&self) -> Result<(), MarketError>
Validate standalone TimeSpec invariants.
TimeSpec::Range is always valid. TimeSpec::Period must have
start < end.
§Errors
Returns MarketError::InvalidPeriod when a period has start >= end.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TimeSpec
impl<'de> Deserialize<'de> for TimeSpec
Source§fn deserialize<D>(
deserializer: D,
) -> Result<TimeSpec, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TimeSpec, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for TimeSpec
Source§impl Serialize for TimeSpec
impl Serialize for TimeSpec
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for TimeSpec
Auto Trait Implementations§
impl Freeze for TimeSpec
impl RefUnwindSafe for TimeSpec
impl Send for TimeSpec
impl Sync for TimeSpec
impl Unpin for TimeSpec
impl UnsafeUnpin for TimeSpec
impl UnwindSafe for TimeSpec
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 more