force-electric 0.1.0

Typed DC electricity, resistance-network, and energy calculations
Documentation
  • Coverage
  • 100%
    44 out of 44 items documented0 out of 36 items with examples
  • Size
  • Source code size: 18.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 499.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hidenoriuehara-art

force-electric

force-electric is a dependency-free Rust library for a compact set of electrical relationships. It uses validated unit types instead of unlabelled numbers and keeps these principles connected:

  • Ohm's law: voltage, current, and resistance;
  • DC power: voltage multiplied by current;
  • series and parallel equivalent resistance;
  • energy: power integrated over time.

Example

use force_electric::{
    Duration, Energy, Resistance, Voltage, DcOperatingPoint, parallel_resistance,
};

let point = DcOperatingPoint::from_voltage_and_resistance(
    Voltage::volts(12.0)?,
    Resistance::ohms(6.0)?,
)?;
assert_eq!(point.current().as_amperes(), 2.0);
assert_eq!(point.power().as_watts(), 24.0);

let energy = Energy::from_power_over(point.power(), Duration::hours(3.0)?)?;
assert_eq!(energy.as_watt_hours(), 72.0);

let parallel = parallel_resistance(&[
    Resistance::ohms(100.0)?,
    Resistance::ohms(100.0)?,
])?;
assert!((parallel.as_ohms() - 50.0).abs() < 1e-12);

# Ok::<(), force_electric::ElectricError>(())

Run the bundled example:

cargo run --example dc_circuit

Scope and safety

The crate models ideal scalar DC relationships. It does not model AC phase, reactance, transients, temperature, component tolerances, insulation, protective devices, or regulatory compliance. It is not a substitute for qualified electrical design or safe measurement practice.

License

MIT