https://github.com/douglau/mag
Library for physical quantities and units
https://github.com/douglau/mag
measurement-units rust si units
Last synced: 6 months ago
JSON representation
Library for physical quantities and units
- Host: GitHub
- URL: https://github.com/douglau/mag
- Owner: DougLau
- License: apache-2.0
- Created: 2019-11-09T23:42:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-13T18:07:45.000Z (over 1 year ago)
- Last Synced: 2025-03-04T08:19:14.423Z (8 months ago)
- Topics: measurement-units, rust, si, units
- Language: Rust
- Homepage:
- Size: 151 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[Mag] is a library for dealing with physical quantities and units.
Quantities are created by multiplying scalar values by a unit type. These units
are named after common abbreviations:```rust
use mag::{length::{ft, m, mi}, time::{h, s}};let a = 1.0 * ft;
assert_eq!(a.to_string(), "1 ft");let b = a.to::();
assert_eq!(b.to_string(), "0.3048 m");let c = 30 * s;
assert_eq!(c.to_string(), "30 s");let d = 60.0 / s;
assert_eq!(d.to_string(), "60 ㎐");let e = 55.0 * mi / h;
assert_eq!(e.to_string(), "55 mi/h");
```## Highlights
* Easy to understand and use
* Performs conversions between units (SI, imperial)
* Units are not discarded when creating quantities
* Fast compile time
* No external dependencies## Alternative
If mag doesn't fit your needs, you could try the [uom] crate, which has many
more features.[mag]: https://docs.rs/mag/latest/mag/
[uom]: https://docs.rs/uom/latest/uom/