[][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.

SymbolNameValue
Yyotta1_000_000_000_000_000_000_000_000
Zzetta1_000_000_000_000_000_000_000
Eexa1_000_000_000_000_000_000
Ppeta1_000_000_000_000_000
Ttera1_000_000_000_000
Ggiga1_000_000_000
Mmega1_000_000
kkilo1_000

The strings can be provided with a decimal, or using the SI symbol as the decimal separator.

StringValue
3k33300
3.3k3300
1M1_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