Skip to main content

human_units/si/
mod.rs

1//! SI (Système international) units.
2//!
3//! All units start with _nano_ and end with _giga_ prefix and use [`u64`](::core::u64) as the underlying type.
4//!
5//! # Caveats
6//!
7#![cfg_attr(
8    feature = "si-units",
9    doc = r##"
10 - [`Time`] uses uncommon units such as *kilseconds*.
11   To use more common _minutes_, _hours_ and _days_ there is [`Duration`](crate::Duration).
12 - [`Mass`] uses *megagrams* instead of *tonnes*."##
13)]
14//! - Some units's symbols as well as _micro_ prefix use Unicode characters.
15//!   Turn off `unicode` feature to replace them with alternative ASCII-only representation.
16
17mod core;
18#[cfg(feature = "si-units")]
19mod units;
20
21pub use self::core::*;
22#[cfg(feature = "si-units")]
23pub use self::units::*;
24
25/// Add SI unit parsing and formatting functions.
26///
27/// The macro adds the following trait implementations:
28/// - [`Display`](::core::fmt::Display)
29/// - [`FromStr`](::core::str::FromStr)
30#[cfg_attr(
31    all(feature = "derive", feature = "serde"),
32    doc = " - [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) when `serde` feature is enabled."
33)]
34///
35/// The macro also adds the following constants:
36/// - `Self::SYMBOL` — the symbol,
37/// - `Self::MAX_STRING_LEN` — max. length in string form.
38///
39/// Macro parameters:
40/// - `symbol` is the unit name without SI prefix, e.g. `"Hz"`, `"°C"`.
41/// - `min_prefix` is the minimum SI prefix, e.g. `"K"`, `"M"`, `""`.
42///   Equals `"nano"` by default.
43/// - `max_prefix` is the maximum SI prefix, e.g. `"G"`, `"T"`.
44///   By default equals the largest prefix an underlying integer type can hold.
45///
46/// # Example
47///
48#[cfg_attr(
49    feature = "derive",
50    doc = r##"```rust
51use human_units::si::si_unit;
52
53#[si_unit(symbol = "Hz")]
54struct CpuFrequency(pub u64);
55```"##
56)]
57#[cfg(feature = "derive")]
58pub use human_units_derive::si_unit;