Skip to main content

CalendarClient

Struct CalendarClient 

Source
pub struct CalendarClient { /* private fields */ }
Expand description

Client responsible for fetching economic calendar releases over HTTP and managing disk caching.

Implementations§

Source§

impl CalendarClient

Source

pub fn default_cache_dir() -> PathBuf

Returns the default platform cache directory for redfolder.

  • On Windows: Respects %LOCALAPPDATA%\redfolder\cache, %APPDATA%\redfolder\cache, or %USERPROFILE%\.cache\redfolder.
  • On Linux/Unix: Respects $XDG_CACHE_HOME/redfolder or $HOME/.cache/redfolder.
  • Fallback: System temporary directory (redfolder_cache).
Source

pub fn try_new(cache_dir: Option<PathBuf>) -> Result<Self>

Create a new CalendarClient with an optional cache directory fallibly.

Source

pub fn new(cache_dir: Option<PathBuf>) -> Self

Create a new CalendarClient with an optional cache directory. If None, defaults to CalendarClient::default_cache_dir().

Source

pub fn try_without_cache() -> Result<Self>

Create a new CalendarClient without any local disk caching fallibly.

Source

pub fn without_cache() -> Self

Create a new CalendarClient without any local disk caching.

Source

pub fn with_user_agent( cache_dir: Option<PathBuf>, user_agent: &str, ) -> Result<Self>

Create a new CalendarClient with a custom User-Agent string.

Source

pub fn with_options( client: Client, calendar_url: impl Into<String>, cache_dir: Option<PathBuf>, request_timeout: Duration, ) -> Self

Create with custom options.

Source

pub fn with_fallback_url(self, url: impl Into<String>) -> Self

Add a fallback calendar endpoint URL used if the primary URL fails.

Source

pub fn with_fallback_urls<I, S>(self, urls: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple fallback calendar endpoint URLs.

Source

pub fn fallback_urls(&self) -> &[String]

Configured fallback calendar URLs.

Source

pub fn calendar_url(&self) -> &str

Primary calendar URL.

Source

pub fn set_calendar_url(&mut self, url: impl Into<String>)

Set the primary calendar URL.

Source

pub fn add_fallback_url(&mut self, url: impl Into<String>)

Add a fallback calendar URL.

Source

pub fn with_max_response_bytes(self, max_bytes: usize) -> Self

Configure the maximum response body size in bytes to prevent unbounded allocations.

Source

pub fn set_max_response_bytes(&mut self, max_bytes: usize)

Set maximum allowable response body size in bytes.

Source

pub fn max_response_bytes(&self) -> usize

Maximum allowable response body size in bytes.

Source

pub fn with_max_event_count(self, max_events: usize) -> Self

Configure the maximum number of raw events permitted from upstream.

Source

pub fn set_max_event_count(&mut self, max_events: usize)

Set maximum allowable raw event count.

Source

pub fn max_event_count(&self) -> usize

Maximum allowable raw event count.

Source

pub fn with_max_retries(self, max_retries: usize) -> Self

Configure maximum HTTP retry attempts for transient errors (429, 408, 5xx).

Source

pub fn max_retries(&self) -> usize

Configured maximum retry attempts.

Source

pub fn with_backoff( self, initial_delay: Duration, max_retry_after: Duration, ) -> Self

Configure exponential backoff parameters.

Source

pub fn backoff_initial_delay(&self) -> Duration

Initial exponential backoff delay duration.

Source

pub fn max_retry_after(&self) -> Duration

Maximum duration allowed for server-specified Retry-After delays.

Source

pub fn with_overall_timeout(self, timeout: Duration) -> Self

Configure an overall wall-clock timeout ceiling spanning all retry attempts and backoffs.

Source

pub fn overall_timeout(&self) -> Option<Duration>

Overall wall-clock timeout ceiling if set.

Source

pub fn with_integrity_validator( self, validator: impl Fn(&[RawCalendarEvent]) -> Result<()> + Send + Sync + 'static, ) -> Self

Configure a custom pluggable integrity validator callback.

Source

pub fn with_timezone(self, tz: Tz) -> Self

Configure the default source timezone for naive calendar timestamps.

Source

pub fn set_calendar_timezone(&mut self, tz: Option<Tz>)

Set the default source timezone for naive calendar timestamps.

Source

pub fn calendar_timezone(&self) -> Option<Tz>

Default source timezone if configured.

Source

pub fn with_max_stale_age(self, max_age: Option<Duration>) -> Self

Configure the maximum allowable age for stale cache fallback on network failures. If None, stale cache fallback is disabled.

Source

pub fn set_max_stale_cache_age(&mut self, max_age: Option<Duration>)

Set maximum allowable age for stale cache fallback.

Source

pub fn max_stale_cache_age(&self) -> Option<Duration>

Configured maximum stale cache age.

Source

pub fn with_ttl(self, ttl: Duration) -> Self

Configure an optional Time-To-Live (TTL) for the local disk cache.

Source

pub fn set_cache_ttl(&mut self, ttl: Option<Duration>)

Set an optional Time-To-Live (TTL) for the local disk cache.

Source

pub fn cache_ttl(&self) -> Option<Duration>

Configured cache TTL if set.

Source

pub fn set_cache_path(&mut self, path: impl AsRef<Path>)

Set an explicit cache file path.

Source

pub fn cache_path(&self) -> Option<&Path>

Cache file path if configured.

Source

pub async fn fetch_remote(&self) -> Result<Vec<RawCalendarEvent>>

Fetch fresh calendar events directly from the remote API with bounded retry, response size checks, and fallback URL failover.

§Latency Ceiling Guarantee

Worst-case wall-clock latency per URL candidate is strictly bounded: with default settings (30s request timeout, 2 retries, 10s max backoff), worst-case latency under total network timeouts is (1 + 2) * 30s + 20s = 110s. Under immediate 429/5xx status responses, worst-case latency is <= 21s.

If an overall_timeout is set, the entire operation across all candidates is terminated when the deadline expires.

Source

pub fn save_cache(&self, events: &[RawCalendarEvent]) -> Result<()>

Save raw calendar events to the local disk cache atomically (if cache path is set).

On Unix systems, applies restrictive file permissions (0600) and directory permissions (0700) to prevent unauthorized access or tampering on shared multi-user hosts.

Source

pub fn load_cache_data(&self) -> Option<CachedCalendarData>

Load full cached calendar data including metadata, with recovery from legacy and corrupted caches.

Source

pub fn load_cache(&self) -> Option<Vec<RawCalendarEvent>>

Load raw calendar events from the local disk cache (if exists and readable).

Source

pub fn is_cache_valid(&self) -> bool

Checks whether the disk cache exists and is within its configured TTL.

Legacy caches (version 0) lacking fetch timestamps are rejected.

Source

pub async fn force_fetch(&self) -> Result<Vec<RawCalendarEvent>>

Fetch fresh calendar events directly from the remote API, bypassing cache, protecting against empty responses overwriting good data, and saving to cache on success.

Source

pub async fn fetch_or_cached(&self) -> Result<Vec<RawCalendarEvent>>

Fetch fresh events from the remote API, automatically saving to cache on success, or falling back to local cache if the remote request fails.

Respects configured cache TTL and protects against empty responses overwriting good data.

Trait Implementations§

Source§

impl Clone for CalendarClient

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 Debug for CalendarClient

Source§

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

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

impl Default for CalendarClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more