pub struct PricingEngine { /* private fields */ }Available on crate feature
tariffs only.Expand description
Prices sessions against Tariffs.
use ocpi_kit::tariffs::{PricingEngine, PricedPeriod, PricedSession, TimeZone};
use ocpi_kit::v2_3_0::tariffs::*;
use ocpi_kit::types::{DateTime, Number};
// "Simple Tariff example € 2 per hour": 2.00/h excl. VAT, 10% VAT, billed per minute.
let tariff = Tariff::builder()
.country_code("DE").party_id("ALL").id("11").currency("EUR")
.elements(vec![TariffElement::builder()
.price_components(vec![PriceComponent {
component_type: TariffDimensionType::Time,
price: "2.00".parse()?,
vat: Some("10.0".parse()?),
step_size: 60,
extensions: Default::default(),
}])
.build()])
.tax_included(TaxIncluded::No)
.last_updated("2015-06-29T20:39:09Z".parse::<DateTime>()?)
.build();
let session = PricedSession::new("2024-01-15T10:00:00Z".parse()?, TimeZone::utc())
.with_period(PricedPeriod {
charging_hours: "2.5".parse()?,
..PricedPeriod::new("2024-01-15T10:00:00Z".parse()?)
})
.ending("2024-01-15T12:30:00Z".parse()?);
let breakdown = PricingEngine::new().price(&session, &[tariff])?;
assert_eq!(breakdown.total_excl_vat.to_string(), "5.00");
assert_eq!(breakdown.total_incl_vat.to_string(), "5.50");Implementations§
Source§impl PricingEngine
impl PricingEngine
Sourcepub fn new() -> Self
pub fn new() -> Self
An engine with the default PricingPolicy.
Sourcepub fn with_policy(policy: PricingPolicy) -> Self
pub fn with_policy(policy: PricingPolicy) -> Self
An engine with a specific policy.
Sourcepub const fn policy(&self) -> &PricingPolicy
pub const fn policy(&self) -> &PricingPolicy
The policy in use.
Sourcepub fn price(
&self,
session: &PricedSession,
tariffs: &[Tariff],
) -> Result<CostBreakdown, PricingError>
pub fn price( &self, session: &PricedSession, tariffs: &[Tariff], ) -> Result<CostBreakdown, PricingError>
Prices session against tariffs.
When several tariffs are given, each charging period uses the one its tariff_id names;
a period with no tariff_id uses the first tariff that is valid at that moment and whose
type matches the session’s charging preference.
§Errors
Returns PricingError when no applicable tariff can be found, or when the session’s
time zone cannot be resolved.
Trait Implementations§
Source§impl Clone for PricingEngine
impl Clone for PricingEngine
Source§fn clone(&self) -> PricingEngine
fn clone(&self) -> PricingEngine
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PricingEngine
impl Debug for PricingEngine
Source§impl Default for PricingEngine
impl Default for PricingEngine
Source§fn default() -> PricingEngine
fn default() -> PricingEngine
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PricingEngine
impl RefUnwindSafe for PricingEngine
impl Send for PricingEngine
impl Sync for PricingEngine
impl Unpin for PricingEngine
impl UnsafeUnpin for PricingEngine
impl UnwindSafe for PricingEngine
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
Mutably borrows from an owned value. Read more