use std::borrow::Cow;
use super::Gas;
use super::timer::GasDuration;
#[derive(Clone, Debug)]
pub struct GasCharge {
pub name: Cow<'static, str>,
pub compute_gas: Gas,
pub other_gas: Gas,
pub elapsed: GasDuration,
}
#[cfg(feature = "testing")]
impl PartialEq for GasCharge {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self.compute_gas == other.compute_gas
&& self.other_gas == other.other_gas
}
}
#[cfg(feature = "testing")]
impl Eq for GasCharge {}
impl GasCharge {
pub fn new(name: impl Into<Cow<'static, str>>, compute_gas: Gas, other_gas: Gas) -> Self {
let name = name.into();
Self {
name,
compute_gas,
other_gas,
elapsed: GasDuration::default(),
}
}
pub fn total(&self) -> Gas {
self.compute_gas + self.other_gas
}
}