pub fn maybe_bin_range<T>(s: &str, min: T, max: T) -> Result<T, String>Expand description
Validates an unsigned integer value that can be base-10 or base-2 within a range.
This combines maybe_bin and number_range, see the
documentation of those functions for details.
ยงExample
This extends the example in maybe_bin, and only allows a range of
addresses from 2 (0b10) to 15 (0b1111).
use clap::Parser;
use clap_num::maybe_bin_range;
fn address_in_range(s: &str) -> Result<u8, String> {
maybe_bin_range(s, 0b10, 0b1111)
}
#[derive(Parser)]
struct Args {
#[clap(short, long, value_parser=address_in_range)]
address: u8,
}