pub struct Budget {
pub amount: u64,
pub unit: String,
pub decimals: u32,
}Expand description
amount / 10^decimals in unit: {"amount": 300000, "unit": "USD", "decimals": 2} is $3,000.00.
Fields§
§amount: u64In the unit’s smallest denomination at decimals.
unit: StringAn ISO 4217 currency code, or any unit both sides agree on.
decimals: u32How many of amount’s digits are after the decimal point.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn new(amount: u64, unit: impl Into<String>, decimals: u32) -> Self
pub fn new(amount: u64, unit: impl Into<String>, decimals: u32) -> Self
A budget of amount in unit at decimals.
Sourcepub fn from_value(value: Option<&Value>) -> Result<Option<Self>>
pub fn from_value(value: Option<&Value>) -> Result<Option<Self>>
A budget from a JSON claim: None when absent or null, and an error
for anything that is not {amount, unit, decimals} with non-negative
integers no larger than 2^53 - 1.
let claim = serde_json::json!({ "amount": 300000, "unit": "USD", "decimals": 2 });
assert_eq!(Budget::from_value(Some(&claim))?, Some(Budget::new(300_000, "USD", 2)));
assert_eq!(Budget::from_value(None)?, None);
assert!(Budget::from_value(Some(&serde_json::json!("$3000"))).is_err());Sourcepub fn same_scale(&self, other: &Budget) -> bool
pub fn same_scale(&self, other: &Budget) -> bool
Whether two budgets count in the same unit at the same scale, so that one can be spent from the other.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Budget
impl<'de> Deserialize<'de> for Budget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Budget
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
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