[−][src]Function clap_num::si_number_range
pub fn si_number_range<T: Ord + PartialOrd + Display>(
s: &str,
min: T,
max: T
) -> 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 within a range.
This effectively combines si_number
and number_range
, see the
documentation for those functions for details.
Example
This extends the example in si_number
, and only allows a range of
resistances from 1k to 999.999k.
use clap::Clap; use clap_num::si_number_range; fn kilo(s: &str) -> Result<u32, String> { si_number_range(s, 1_000, 999_999) } #[derive(Clap)] struct Args { #[clap(short, long, parse(try_from_str=kilo))] resistance: u32, }