clap_builder/util/
color.rs1use crate::builder::PossibleValue;
2use crate::derive::ValueEnum;
3
4#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ColorChoice {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ColorChoice::Auto => "Auto",
ColorChoice::Always => "Always",
ColorChoice::Never => "Never",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ColorChoice { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ColorChoice {
#[inline]
fn clone(&self) -> ColorChoice { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for ColorChoice {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for ColorChoice {
#[inline]
fn eq(&self, other: &ColorChoice) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::default::Default for ColorChoice {
#[inline]
fn default() -> ColorChoice { Self::Auto }
}Default)]
6pub enum ColorChoice {
7 #[default]
27 Auto,
28
29 Always,
43
44 Never,
58}
59
60impl ColorChoice {
61 pub fn possible_values() -> impl Iterator<Item = PossibleValue> {
63 Self::value_variants()
64 .iter()
65 .filter_map(ValueEnum::to_possible_value)
66 }
67}
68
69impl std::fmt::Display for ColorChoice {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 self.to_possible_value()
72 .expect("no values are skipped")
73 .get_name()
74 .fmt(f)
75 }
76}
77
78impl std::str::FromStr for ColorChoice {
79 type Err = String;
80
81 fn from_str(s: &str) -> Result<Self, Self::Err> {
82 for variant in Self::value_variants() {
83 if variant.to_possible_value().unwrap().matches(s, false) {
84 return Ok(*variant);
85 }
86 }
87 Err(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("invalid variant: {0}", s))
})format!("invalid variant: {s}"))
88 }
89}
90
91impl ValueEnum for ColorChoice {
92 fn value_variants<'a>() -> &'a [Self] {
93 &[Self::Auto, Self::Always, Self::Never]
94 }
95
96 fn to_possible_value(&self) -> Option<PossibleValue> {
97 Some(match self {
98 Self::Auto => PossibleValue::new("auto"),
99 Self::Always => PossibleValue::new("always"),
100 Self::Never => PossibleValue::new("never"),
101 })
102 }
103}