pub struct PriceDatabase { /* private fields */ }Expand description
Database of currency prices.
Stores prices as a map from base currency to a list of (date, price, quote currency). Prices are kept sorted by date for efficient lookup.
Implementations§
Source§impl PriceDatabase
impl PriceDatabase
Sourcepub fn from_directives(directives: &[Directive]) -> Self
pub fn from_directives(directives: &[Directive]) -> Self
Build a price database from directives.
Sourcepub fn add_price(&mut self, price: &PriceDirective)
pub fn add_price(&mut self, price: &PriceDirective)
Add a price directive to the database.
Sourcepub fn get_price(
&self,
base: &str,
quote: &str,
date: NaiveDate,
) -> Option<Decimal>
pub fn get_price( &self, base: &str, quote: &str, date: NaiveDate, ) -> Option<Decimal>
Get the price of a currency on or before a given date.
Returns the most recent price for the base currency in terms of the quote currency. Tries direct lookup, inverse lookup, and chained lookup (A→B→C).
Sourcepub fn get_latest_price(&self, base: &str, quote: &str) -> Option<Decimal>
pub fn get_latest_price(&self, base: &str, quote: &str) -> Option<Decimal>
Get the latest price of a currency (most recent date).
Sourcepub fn convert(
&self,
amount: &Amount,
to_currency: &str,
date: NaiveDate,
) -> Option<Amount>
pub fn convert( &self, amount: &Amount, to_currency: &str, date: NaiveDate, ) -> Option<Amount>
Convert an amount to a target currency.
Returns the converted amount, or None if no price is available.
Sourcepub fn convert_latest(
&self,
amount: &Amount,
to_currency: &str,
) -> Option<Amount>
pub fn convert_latest( &self, amount: &Amount, to_currency: &str, ) -> Option<Amount>
Convert an amount using the latest available price.
Sourcepub fn currencies(&self) -> impl Iterator<Item = &str>
pub fn currencies(&self) -> impl Iterator<Item = &str>
Get all currencies that have prices defined.
Sourcepub fn has_prices(&self, currency: &str) -> bool
pub fn has_prices(&self, currency: &str) -> bool
Check if a currency has any prices defined.
Trait Implementations§
Source§impl Debug for PriceDatabase
impl Debug for PriceDatabase
Source§impl Default for PriceDatabase
impl Default for PriceDatabase
Source§fn default() -> PriceDatabase
fn default() -> PriceDatabase
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PriceDatabase
impl RefUnwindSafe for PriceDatabase
impl Send for PriceDatabase
impl Sync for PriceDatabase
impl Unpin for PriceDatabase
impl UnwindSafe for PriceDatabase
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Mutably borrows from an owned value. Read more
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.