| 1 |
use crate::VariantCase; |
| 2 |
|
| 3 |
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] |
| 4 |
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 5 |
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] |
| 6 |
pub struct Variant { |
| 7 |
pub(crate) cases: Vec<VariantCase>, |
| 8 |
} |
| 9 |
|
| 10 |
impl Variant { |
| 11 |
pub fn empty() -> Self { |
| 12 |
Self::default() |
| 13 |
} |
| 14 |
|
| 15 |
pub fn case(&mut self, case: impl Into<VariantCase>) { |
| 16 |
self.cases.push(case.into()); |
| 17 |
} |
| 18 |
|
| 19 |
pub fn cases(&self) -> &[VariantCase] { |
| 20 |
&self.cases |
| 21 |
} |
| 22 |
|
| 23 |
pub fn cases_mut(&mut self) -> &mut Vec<VariantCase> { |
| 24 |
&mut self.cases |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl<I, C> From<I> for Variant |
| 29 |
where |
| 30 |
I: IntoIterator<Item = C>, |
| 31 |
C: Into<VariantCase>, |
| 32 |
{ |
| 33 |
fn from(value: I) -> Self { |
| 34 |
Self { |
| 35 |
cases: value.into_iter().map(|c| c.into()).collect(), |
| 36 |
} |
| 37 |
} |
| 38 |
} |