| Crates.io | ohms |
| lib.rs | ohms |
| version | 0.4.0 |
| created_at | 2023-02-02 21:15:36.518899+00 |
| updated_at | 2023-02-23 06:22:33.098613+00 |
| description | Electrical units library for embedded targets |
| homepage | |
| repository | https://github.com/UnderLogic/ohms |
| max_upload_size | |
| id | 775084 |
| size | 70,930 |
Electrical units library for embedded Rust targets focusing on ease-of-use and performance.
Supports no_std environments.
Greatly inspired by the fugit crate.
All units are stored internally as u64 or i64 in their base unit.
Types implement their own FromInteger and FromFloat traits for convenience on the following types:
u8u16u32u64i8i16i32i64f32f64The Current, Resistance and Voltage types follow the Ohm's Law rules.
This means that you can use the / and * operators to calculate the missing value.
For example, Voltage / Current will return a Resistance value.
The Power type supports calculating the power from multiplying Voltage and Current values.
You can add this crate via crates.io:
$ cargo add ohms
use ohms::prelude::*;
let voltage = 5.volts();
let current = 1.milli_amps();
let resistance = voltage / current;
let power = voltage * current;
assert_eq!(resistance.ohms(), 5000);
assert_eq!(power.milli_watts(), 5000);
You can find the documentation here.