Skip to main content

finance_query/providers/adapter/
mod.rs

1//! Provider adapter traits — one trait per [`Capability`].
2//!
3//! A provider bridge implements [`ProviderCore`] plus the capability traits it
4//! actually serves, then overrides the matching `as_*` accessors on
5//! [`ProviderAdapter`] to return `Some(self)`. `ProviderAdapter::capabilities`
6//! is *derived* from those accessors, so a provider's declared capability set
7//! can never drift from what it implements.
8//!
9//! Within a capability trait, the primary operation is required (implementing
10//! the trait without it is unrepresentable) while secondary operations default
11//! to [`FinanceError::NotSupported`]; dispatch ([`super::ProviderSet::fetch`])
12//! skips `NotSupported` and falls through to the next routed provider, so
13//! ragged per-operation coverage degrades gracefully.
14
15use super::{Operation, Provider};
16use crate::error::FinanceError;
17
18/// Identity shared by every capability trait: the provider id and the
19/// `NotSupported` error constructor used by default method bodies.
20pub trait ProviderCore: Send + Sync {
21    /// This provider's identity, used for routing and health reporting.
22    fn id(&self) -> Provider;
23
24    /// The error a default method body returns for an unimplemented operation.
25    fn not_supported(&self, operation: Operation) -> FinanceError {
26        operation.not_supported(self.id())
27    }
28}
29
30mod dispatch;
31mod equity;
32mod markets;
33
34pub use dispatch::ProviderAdapter;
35pub use equity::{
36    ChartProvider, CorporateProvider, FilingsProvider, FundamentalsProvider, OptionsProvider,
37    QuoteProvider,
38};
39pub use markets::CryptoProvider;
40pub use markets::EconomicProvider;
41pub use markets::ForexProvider;
42pub use markets::{
43    CalendarProvider, CommoditiesProvider, DiscoveryProvider, FuturesProvider, IndicesProvider,
44    MarketProvider,
45};