pub struct MeterSet {
pub meters: HashMap<MeterKind, u64>,
}Expand description
A collection of meter readings, keyed by MeterKind.
Uses HashMap to guarantee no duplicate MeterKind entries.
Use MeterSet::insert() to add values - it will accumulate
quantities for the same key instead of overwriting.
Fields§
§meters: HashMap<MeterKind, u64>Implementations§
Source§impl MeterSet
impl MeterSet
Sourcepub fn accumulate(
&mut self,
kind: MeterKind,
quantity: u64,
) -> Result<(), MeterSetError>
pub fn accumulate( &mut self, kind: MeterKind, quantity: u64, ) -> Result<(), MeterSetError>
Insert or accumulate a meter reading.
If the key already exists, the quantity is added to the existing value.
Uses checked_add to prevent u64 overflow.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MeterSet
impl<'de> Deserialize<'de> for MeterSet
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
Auto Trait Implementations§
impl Freeze for MeterSet
impl RefUnwindSafe for MeterSet
impl Send for MeterSet
impl Sync for MeterSet
impl Unpin for MeterSet
impl UnsafeUnpin for MeterSet
impl UnwindSafe for MeterSet
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