mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 15:46:36 +00:00
Add compile-time length checking for Strategy
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
ebafba4e9b
commit
5e62012ce3
1 changed files with 13 additions and 5 deletions
|
@ -434,13 +434,17 @@ impl Default for RateLimit {
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub(crate) struct StrategyWrapped(pub(crate) Strategy);
|
pub(crate) struct StrategyWrapped(pub(crate) Strategy);
|
||||||
|
|
||||||
impl ValueEnum for StrategyWrapped {
|
impl StrategyWrapped {
|
||||||
fn value_variants<'a>() -> &'a [Self] {
|
const VARIANTS: &'static [Self; 3] = &[
|
||||||
&[
|
|
||||||
Self(Strategy::CrateMetaData),
|
Self(Strategy::CrateMetaData),
|
||||||
Self(Strategy::QuickInstall),
|
Self(Strategy::QuickInstall),
|
||||||
Self(Strategy::Compile),
|
Self(Strategy::Compile),
|
||||||
]
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ValueEnum for StrategyWrapped {
|
||||||
|
fn value_variants<'a>() -> &'a [Self] {
|
||||||
|
Self::VARIANTS
|
||||||
}
|
}
|
||||||
fn to_possible_value(&self) -> Option<PossibleValue> {
|
fn to_possible_value(&self) -> Option<PossibleValue> {
|
||||||
Some(PossibleValue::new(self.0.to_str()))
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use strum::VariantArray;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_cli() {
|
fn verify_cli() {
|
||||||
Args::command().debug_assert()
|
Args::command().debug_assert()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _: () = assert!(Strategy::VARIANTS.len() == StrategyWrapped::VARIANTS.len());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue