pub struct Opts<ID: 'static> {
options: &'static[Opt<ID>],
flag_chars: &'static str,
description: Option<&'static str>,
}
type RequiredParamsBitSet = ordered_bitset::OrderedBitSet<u32, 4>;
pub const MAX_REQUIRED_OPTIONS: usize = RequiredParamsBitSet::CAPACITY;
impl<ID: 'static> Opts<ID> {
pub const fn new(options: &'static[Opt<ID>]) -> Self {
let mut opt_idx = 0;
let mut num_required_parameters = 0;
while opt_idx < options.len() {
if matches!(options[opt_idx].r#type, OptType::Flag | OptType::Value) && options[opt_idx].is_required() {
num_required_parameters += 1;
}
opt_idx += 1;
}
assert!(num_required_parameters <= RequiredParamsBitSet::CAPACITY,
"More than 128 non-positional required option entries is not supported at this time");
Self {
options,
flag_chars: "-",
description: None,
}
}
pub const fn with_flag_chars(mut self, flag_chars: &'static str) -> Self {
self.flag_chars = flag_chars;
self
}
pub const fn with_description(mut self, description: &'static str) -> Self {
self.description = Some(description);
self
}
}