pub struct Soc(/* private fields */);Expand description
State of charge as a fraction in [0, 1].
Constructed strictly, because a SoC outside the interval is either a driver
bug or a unit mix-up (percent vs. fraction) and both are worth failing on.
Soc::clamped exists for sensor noise around the endpoints.
Implementations§
Source§impl Soc
impl Soc
Sourcepub const ZERO_RESERVE: Self
pub const ZERO_RESERVE: Self
No backup reserve — the default for a battery that keeps nothing back.
Sourcepub fn new(fraction: f64) -> Result<Self, UnitError>
pub fn new(fraction: f64) -> Result<Self, UnitError>
A state of charge from a fraction in [0, 1].
§Errors
UnitError::SocOutOfRange when the value is outside [0, 1] or not finite.
Sourcepub fn from_percent(percent: f64) -> Result<Self, UnitError>
pub fn from_percent(percent: f64) -> Result<Self, UnitError>
A state of charge from a percentage in [0, 100].
§Errors
UnitError::SocOutOfRange when the value is outside [0, 100].
Sourcepub fn clamped(fraction: f64) -> Self
pub fn clamped(fraction: f64) -> Self
A state of charge clamped into [0, 1] — for sensors that report 100.4 %.
A non-finite input becomes Soc::EMPTY, the safe end for every decision
that reads a SoC (never discharge on a broken reading).
Trait Implementations§
impl Copy for Soc
Source§impl<'de> Deserialize<'de> for Soc
impl<'de> Deserialize<'de> for Soc
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
Source§impl PartialOrd for Soc
impl PartialOrd for Soc
impl StructuralPartialEq for Soc
Auto Trait Implementations§
impl Freeze for Soc
impl RefUnwindSafe for Soc
impl Send for Soc
impl Sync for Soc
impl Unpin for Soc
impl UnsafeUnpin for Soc
impl UnwindSafe for Soc
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