Add compile-time length checking for Strategy

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-07-23 00:43:32 +10:00
parent ebafba4e9b
commit 5e62012ce3
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928

View file

@ -434,13 +434,17 @@ impl Default for RateLimit {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub(crate) struct StrategyWrapped(pub(crate) Strategy);
impl StrategyWrapped {
const VARIANTS: &'static [Self; 3] = &[
Self(Strategy::CrateMetaData),
Self(Strategy::QuickInstall),
Self(Strategy::Compile),
];
}
impl ValueEnum for StrategyWrapped {
fn value_variants<'a>() -> &'a [Self] {
&[
Self(Strategy::CrateMetaData),
Self(Strategy::QuickInstall),
Self(Strategy::Compile),
]
Self::VARIANTS
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(PossibleValue::new(self.0.to_str()))
@ -598,10 +602,14 @@ You cannot use --{option} and specify multiple packages at the same time. Do one
#[cfg(test)]
mod test {
use strum::VariantArray;
use super::*;
#[test]
fn verify_cli() {
Args::command().debug_assert()
}
const _: () = assert!(Strategy::VARIANTS.len() == StrategyWrapped::VARIANTS.len());
}