[−][src]Function clap_num::si_number
pub fn si_number<T>(s: &str) -> Result<T, String> where
<T as TryFrom<u128>>::Error: Display,
<T as FromStr>::Err: Display,
T: CheckedAdd,
T: CheckedMul,
T: CheckedSub,
T: FromStr,
T: PartialOrd,
T: TryFrom<u128>,
T: Zero,
Validate a signed or unsigned integer value with a metric prefix.
This can accept strings with the (case sensitive) SI symbols.
Symbol | Name | Value |
---|---|---|
Y | yotta | 1_000_000_000_000_000_000_000_000 |
Z | zetta | 1_000_000_000_000_000_000_000 |
E | exa | 1_000_000_000_000_000_000 |
P | peta | 1_000_000_000_000_000 |
T | tera | 1_000_000_000_000 |
G | giga | 1_000_000_000 |
M | mega | 1_000_000 |
k | kilo | 1_000 |
The strings can be provided with a decimal, or using the SI symbol as the decimal separator.
String | Value |
---|---|
3k3 | 3300 |
3.3k | 3300 |
1M | 1_000_000 |
Example
This allows for resistance value to be passed using SI symbols.
use clap::Clap; use clap_num::si_number; #[derive(Clap)] struct Args { #[clap(short, long, parse(try_from_str=si_number))] resistance: u128, }
To run this example use cargo run --example resistance
, giving arguments
to the program after --
, for example:
$ cargo run --example resistance -- --resistance 1M1
Resistance: 1100000 ohms