Expand description
Electrical unit types for embedded targets focusing on ease-of-use and performance
Supported units:
- Current (μA, mA, A)
- Resistance (mΩ, Ω, kΩ, MΩ)
- Voltage (μV, mV, V, kV)
- Power (μW, mW, W, kW)
Each unit type has a corresponding extension trait for creating values from integer and floating point values.
Unit types can easily be converted to and from different denominations.
Ohm’s Law is implemented for Voltage and Current types, allowing you to easily calculate
between the three units using the / and * operators.
§Examples
Determine the resistance of a 5V, 1A load:
use ohms::prelude::*;
let voltage = 5.volts();
let current = 1.amps();
let resistance = voltage / current; // 5V / 1A = 5Ω
println!("Resistance: {} Ω", resistance.ohms());Determine the current of a 5V, 220Ω load:
use ohms::prelude::*;
let voltage = 5.volts();
let resistance = 220.ohms();
let current = voltage / resistance; // 5V / 220Ω = 22.72mA
println!("Current: {} mA", current.milli_amps());Determine the voltage of a 0.5A, 4.7kΩ load:
use ohms::prelude::*;
let current = 0.5.milli_amps();
let resistance = 4.7.kilo_ohms();
let voltage = current * resistance; // 0.5mA * 4.7kΩ = 2.35V
println!("Voltage: {} V", voltage.volts());Modules§
Macros§
Structs§
- Current
- Represents a current value, stored as whole microamps (μA) as a 64-bit value. This value can only be positive.
- Power
- Represents a power value, stored as whole microwatts (μW) as a 64-bit value. This value can only be positive.
- Resistance
- Represents a resistance value, stored as whole milliohms (mΩ) as a 64-bit value. This value can only be positive.
- Voltage
- Represents a voltage value, stored as whole microvolts (μV) as a signed 64-bit value. This value can be positive or negative.
Traits§
- Current
From Float - Extension trait for simple short-hands for creating
Currentvalues from floating-point values. - Current
From Integer - Extension trait for simple short-hands for creating
Currentvalues from integer values. - Power
From Float - Extension trait for simple short-hands for creating
Powervalues from floating-point values. - Power
From Integer - Extension trait for simple short-hands for creating
Powervalues from integer values. - Resistance
From Float - Extension trait for simple short-hands for creating
Resistancevalues from floating-point values. - Resistance
From Integer - Extension trait for simple short-hands for creating
Resistancevalues from integer values. - Voltage
From Float - Extension trait for simple short-hands for creating
Voltagevalues from floating-point values. - Voltage
From Integer - Extension trait for simple short-hands for creating
Voltagevalues from integer values.