Skip to main content

sie_sdk/types/
estimate.rs

1//! Cost estimation for a request that has not been sent yet.
2
3// Wire-mirror types: field names are the API contract itself, and the ones whose
4// meaning is not obvious carry their own doc comment.
5#![allow(missing_docs)]
6
7use std::collections::HashMap;
8
9use serde::{Deserialize, Serialize};
10
11/// One priced unit and its exact rational rate.
12///
13/// Credits are integers and rates are exact rationals: multiply and round once, never per
14/// unit, or the totals will not reconcile with the server's.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct AppliedRate {
17    pub unit: String,
18    pub rate_numerator: i64,
19    pub rate_denominator: i64,
20}
21
22/// What the rate book priced this request as.
23#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
24pub struct RateIdentity {
25    #[serde(default, deserialize_with = "crate::types::null_as_default")]
26    pub model: String,
27    #[serde(default, deserialize_with = "crate::types::null_as_default")]
28    pub profile: String,
29    #[serde(default, deserialize_with = "crate::types::null_as_default")]
30    pub operation: String,
31    #[serde(default, deserialize_with = "crate::types::null_as_default")]
32    pub region: String,
33}
34
35/// The estimated cost of a request.
36#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
37pub struct CostEstimate {
38    #[serde(default, deserialize_with = "crate::types::null_as_default")]
39    pub endpoint: String,
40    #[serde(default, deserialize_with = "crate::types::null_as_default")]
41    pub identity: RateIdentity,
42    #[serde(default, deserialize_with = "crate::types::null_as_default")]
43    pub estimated_credits: u64,
44    /// Upper bound assumed for each priced unit.
45    #[serde(default, deserialize_with = "crate::types::null_as_default")]
46    pub unit_ceilings: HashMap<String, u64>,
47    #[serde(default, deserialize_with = "crate::types::null_as_default")]
48    pub applied_rates: Vec<AppliedRate>,
49    #[serde(default, deserialize_with = "crate::types::null_as_default")]
50    pub rate_book_version: String,
51    #[serde(default, deserialize_with = "crate::types::null_as_default")]
52    pub rate_book_sha256: String,
53    #[serde(default, deserialize_with = "crate::types::null_as_default")]
54    pub rounding_rule: String,
55    #[serde(default, deserialize_with = "crate::types::null_as_default")]
56    pub estimate_basis: String,
57    /// Meaningful only for duration-priced identities; `null` otherwise.
58    #[serde(default)]
59    pub minimum_billed_units: Option<HashMap<String, u64>>,
60}