Function clap_num::maybe_hex_range [−][src]
pub fn maybe_hex_range<T: Num + Unsigned>(
s: &str,
min: T,
max: T
) -> Result<T, String> where
<T as Num>::FromStrRadixErr: Display,
<T as FromStr>::Err: Display,
T: FromStr,
T: Display,
T: Ord,
Expand description
Validates an unsigned integer value that can be base-10 or base-16 within a range.
This effectively combines maybe_hex
and number_range
, see the
documentation for those functions for details.
Example
This extends the example in maybe_hex
, and only allows a range of
addresses from 0x100
to 0x200
.
use clap::Parser;
use clap_num::maybe_hex_range;
fn address_in_range(s: &str) -> Result<u32, String> {
maybe_hex_range(s, 0x100, 0x200)
}
#[derive(Parser)]
struct Args {
#[clap(short, long, parse(try_from_str=address_in_range))]
address: u32,
}