codama_koroks/
enum_variant_korok.rs1use crate::{FieldsKorok, KorokTrait};
2use codama_attributes::Attributes;
3use codama_errors::{combine_errors, CodamaError, CodamaResult, IteratorCombineErrors};
4use codama_nodes::Node;
5
6#[derive(Debug, PartialEq)]
7pub struct EnumVariantKorok<'a> {
8 pub ast: &'a syn::Variant,
9 pub attributes: Attributes<'a>,
10 pub fields: FieldsKorok<'a>,
11 pub node: Option<Node>,
12}
13
14impl<'a> EnumVariantKorok<'a> {
15 pub fn parse(ast: &'a syn::Variant) -> CodamaResult<Self> {
16 let (attributes, fields) = combine_errors!(
17 Attributes::parse(&ast.attrs, ast.into()).map_err(CodamaError::from),
18 FieldsKorok::parse(&ast.fields),
19 )?;
20 Ok(Self {
21 ast,
22 attributes,
23 fields,
24 node: None,
25 })
26 }
27
28 pub fn parse_all(
29 variants: &'a syn::punctuated::Punctuated<syn::Variant, syn::Token![,]>,
30 ) -> CodamaResult<Vec<Self>> {
31 variants
32 .iter()
33 .map(Self::parse)
34 .collect_and_combine_errors()
35 }
36}
37
38impl KorokTrait for EnumVariantKorok<'_> {
39 fn node(&self) -> &Option<Node> {
40 &self.node
41 }
42
43 fn set_node(&mut self, node: Option<Node>) {
44 self.node = node;
45 }
46
47 fn attributes(&self) -> Option<&Attributes> {
48 Some(&self.attributes)
49 }
50}