Skip to main content

Soc

Struct Soc 

Source
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

Source

pub const EMPTY: Self

Empty.

Source

pub const ZERO_RESERVE: Self

No backup reserve — the default for a battery that keeps nothing back.

Source

pub const FULL: Self

Full.

Source

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.

Source

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].

Source

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).

Source

pub const fn fraction(self) -> f64

The fraction in [0, 1].

Source

pub fn percent(self) -> f64

The percentage in [0, 100].

Source

pub fn energy_in(self, capacity: Energy) -> Energy

The energy stored in a battery of capacity at this state of charge.

Trait Implementations§

Source§

impl Clone for Soc

Source§

fn clone(&self) -> Soc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Soc

Source§

impl Debug for Soc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Soc

Source§

fn default() -> Soc

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Soc

Source§

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 Display for Soc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Soc> for f64

Source§

fn from(value: Soc) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Soc

Source§

fn eq(&self, other: &Soc) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Soc

Source§

fn partial_cmp(&self, other: &Soc) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Soc

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Soc

Source§

impl TryFrom<f64> for Soc

Source§

type Error = UnitError

The type returned in the event of a conversion error.
Source§

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.