pub struct Energy(/* private fields */);Expand description
A finite, non-negative amount of energy stored in joules.
Implementations§
Source§impl Energy
impl Energy
Sourcepub fn joules(value: f64) -> Result<Self, ElectricError>
pub fn joules(value: f64) -> Result<Self, ElectricError>
Creates an energy amount in joules.
Sourcepub fn watt_hours(value: f64) -> Result<Self, ElectricError>
pub fn watt_hours(value: f64) -> Result<Self, ElectricError>
Creates an energy amount in watt-hours.
Sourcepub fn from_power_over(
power: Power,
duration: Duration,
) -> Result<Self, ElectricError>
pub fn from_power_over( power: Power, duration: Duration, ) -> Result<Self, ElectricError>
Calculates energy consumed by constant power over a duration.
Examples found in repository?
examples/dc_circuit.rs (line 10)
5fn main() -> Result<(), force_electric::ElectricError> {
6 let point = DcOperatingPoint::from_voltage_and_resistance(
7 Voltage::volts(12.0)?,
8 Resistance::ohms(6.0)?,
9 )?;
10 let energy = Energy::from_power_over(point.power(), Duration::hours(3.0)?)?;
11
12 let resistors = [Resistance::ohms(100.0)?, Resistance::ohms(100.0)?];
13 let series = series_resistance(&resistors)?;
14 let parallel = parallel_resistance(&resistors)?;
15
16 println!("current: {:.2} A", point.current().as_amperes());
17 println!("power: {:.2} W", point.power().as_watts());
18 println!("energy over 3 h: {:.2} Wh", energy.as_watt_hours());
19 println!("series resistance: {:.2} ohm", series.as_ohms());
20 println!("parallel resistance: {:.2} ohm", parallel.as_ohms());
21
22 Ok(())
23}Sourcepub fn as_watt_hours(self) -> f64
pub fn as_watt_hours(self) -> f64
Returns energy in watt-hours.
Examples found in repository?
examples/dc_circuit.rs (line 18)
5fn main() -> Result<(), force_electric::ElectricError> {
6 let point = DcOperatingPoint::from_voltage_and_resistance(
7 Voltage::volts(12.0)?,
8 Resistance::ohms(6.0)?,
9 )?;
10 let energy = Energy::from_power_over(point.power(), Duration::hours(3.0)?)?;
11
12 let resistors = [Resistance::ohms(100.0)?, Resistance::ohms(100.0)?];
13 let series = series_resistance(&resistors)?;
14 let parallel = parallel_resistance(&resistors)?;
15
16 println!("current: {:.2} A", point.current().as_amperes());
17 println!("power: {:.2} W", point.power().as_watts());
18 println!("energy over 3 h: {:.2} Wh", energy.as_watt_hours());
19 println!("series resistance: {:.2} ohm", series.as_ohms());
20 println!("parallel resistance: {:.2} ohm", parallel.as_ohms());
21
22 Ok(())
23}Sourcepub fn runtime_at(self, power: Power) -> Result<Duration, ElectricError>
pub fn runtime_at(self, power: Power) -> Result<Duration, ElectricError>
Calculates how long this energy can supply constant, positive power.
Trait Implementations§
impl Copy for Energy
Source§impl PartialOrd for Energy
impl PartialOrd for Energy
impl StructuralPartialEq for Energy
Auto Trait Implementations§
impl Freeze for Energy
impl RefUnwindSafe for Energy
impl Send for Energy
impl Sync for Energy
impl Unpin for Energy
impl UnsafeUnpin for Energy
impl UnwindSafe for Energy
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