---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_with_multiple_type_params"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST)]
  pub struct MultiType {
      union_field: NodeId<crate::Type1, crate::Type2>,
      triple_field: NodeId<crate::Type1, crate::Type2, crate::Type3>,
      vec_multi: Vec<crate::Type1, crate::Type2>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct MultiType {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: crate::SyntaxId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) union_field: crate::NodeId,
      pub(crate) triple_field: crate::NodeId,
      pub(crate) vec_multi: Vec<crate::NodeId>,
  }
  impl MultiType {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> crate::SyntaxId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod multi_type_field {
      #[derive(Debug)]
      pub enum UnionField<'ast> {
          Type1(&'ast crate::Type1),
          Type2(&'ast crate::Type2),
          Error,
      }
      impl<'ast> UnionField<'ast> {
          pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
              match self {
                  Self::Error => Err(crate::invalid_node_error()),
                  _ => Ok(()),
              }
          }
          pub fn from_node(node: &'ast crate::Node) -> Option<UnionField<'ast>> {
              Some(Self::from(node))
          }
      }
      impl<'ast> From<&'ast crate::Node> for UnionField<'ast> {
          fn from(n: &'ast crate::Node) -> Self {
              match n {
                  crate::Node::Type1(val) => UnionField::Type1(val),
                  crate::Node::Type2(val) => UnionField::Type2(val),
                  _ => UnionField::Error,
              }
          }
      }
      impl<'ast> From<&'ast crate::Type1> for UnionField<'ast> {
          fn from(v: &'ast crate::Type1) -> Self {
              Self::Type1(v)
          }
      }
      impl<'ast> From<&'ast crate::Type2> for UnionField<'ast> {
          fn from(v: &'ast crate::Type2) -> Self {
              Self::Type2(v)
          }
      }
      #[derive(Debug)]
      pub enum TripleField<'ast> {
          Type1(&'ast crate::Type1),
          Type2(&'ast crate::Type2),
          Type3(&'ast crate::Type3),
          Error,
      }
      impl<'ast> TripleField<'ast> {
          pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
              match self {
                  Self::Error => Err(crate::invalid_node_error()),
                  _ => Ok(()),
              }
          }
          pub fn from_node(node: &'ast crate::Node) -> Option<TripleField<'ast>> {
              Some(Self::from(node))
          }
      }
      impl<'ast> From<&'ast crate::Node> for TripleField<'ast> {
          fn from(n: &'ast crate::Node) -> Self {
              match n {
                  crate::Node::Type1(val) => TripleField::Type1(val),
                  crate::Node::Type2(val) => TripleField::Type2(val),
                  crate::Node::Type3(val) => TripleField::Type3(val),
                  _ => TripleField::Error,
              }
          }
      }
      impl<'ast> From<&'ast crate::Type1> for TripleField<'ast> {
          fn from(v: &'ast crate::Type1) -> Self {
              Self::Type1(v)
          }
      }
      impl<'ast> From<&'ast crate::Type2> for TripleField<'ast> {
          fn from(v: &'ast crate::Type2) -> Self {
              Self::Type2(v)
          }
      }
      impl<'ast> From<&'ast crate::Type3> for TripleField<'ast> {
          fn from(v: &'ast crate::Type3) -> Self {
              Self::Type3(v)
          }
      }
      #[derive(Debug)]
      pub enum VecMulti<'ast> {
          Type1(&'ast crate::Type1),
          Type2(&'ast crate::Type2),
          Error,
      }
      impl<'ast> VecMulti<'ast> {
          pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
              match self {
                  Self::Error => Err(crate::invalid_node_error()),
                  _ => Ok(()),
              }
          }
          pub fn from_node(node: &'ast crate::Node) -> Option<VecMulti<'ast>> {
              Some(Self::from(node))
          }
      }
      impl<'ast> From<&'ast crate::Node> for VecMulti<'ast> {
          fn from(n: &'ast crate::Node) -> Self {
              match n {
                  crate::Node::Type1(val) => VecMulti::Type1(val),
                  crate::Node::Type2(val) => VecMulti::Type2(val),
                  _ => VecMulti::Error,
              }
          }
      }
      impl<'ast> From<&'ast crate::Type1> for VecMulti<'ast> {
          fn from(v: &'ast crate::Type1) -> Self {
              Self::Type1(v)
          }
      }
      impl<'ast> From<&'ast crate::Type2> for VecMulti<'ast> {
          fn from(v: &'ast crate::Type2) -> Self {
              Self::Type2(v)
          }
      }
  }
  #[allow(unused)]
  impl MultiType {
      ///Returns the `union_field` field
      pub fn get_union_field<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<multi_type_field::UnionField<'ast>> {
          {
              let union_field = &self.union_field;
              ast.node(*union_field)
                  .and_then(|node| multi_type_field::UnionField::from_node(node))
          }
      }
      ///Returns the `triple_field` field
      pub fn get_triple_field<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<multi_type_field::TripleField<'ast>> {
          {
              let triple_field = &self.triple_field;
              ast.node(*triple_field)
                  .and_then(|node| multi_type_field::TripleField::from_node(node))
          }
      }
      ///Returns the `vec_multi` field
      pub fn get_vec_multi<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Vec<multi_type_field::VecMulti<'ast>> {
          {
              let vec_multi = &self.vec_multi;
              vec_multi
                  .iter()
                  .filter_map(|n| {
                      ast
                          .node(*n)
                          .and_then(|node| multi_type_field::VecMulti::from_node(node))
                  })
                  .collect::<Vec<_>>()
          }
      }
  }
  #[allow(unused)]
  impl<'ast> MultiType {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          self.get_union_field(ast).unwrap().validate(ast).unwrap();
          self.get_triple_field(ast).unwrap().validate(ast).unwrap();
          self.get_vec_multi(ast).iter().map(|f| f.validate(ast).unwrap());
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for MultiType {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "MultiType"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for MultiType {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "MultiType"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for MultiType {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"MultiType",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for MultiType {
      fn node_with_state(
          &self,
          b: &mut bluegum::Builder,
          state: &crate::Printer<'tokens>,
      ) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"MultiType",
              ),
          );
          if let Some(cst_node) = state.get_syntax(self.syntax) {
              let span = cst_node.span();
              if let Some(span_data) = span.data(state.get_span_cache()) {
                  b.debug(
                      "span",
                      format!("{}..{}", span_data.start, span_data.start + span_data.len),
                  );
              }
          }
          if let Some(meta) = self.meta {
              b.add_node_with_state(state, &"meta".blue().italic().to_string(), &meta);
          }
          {
              {
                  let union_field = &self.union_field;
                  b.add_node_with_state(state, stringify!(union_field), union_field);
              };
              {
                  let triple_field = &self.triple_field;
                  b.add_node_with_state(state, stringify!(triple_field), triple_field);
              };
              {
                  let vec_multi = &self.vec_multi;
                  b.add_nodes_of_builders(
                      stringify!(vec_multi),
                      vec_multi
                          .iter()
                          .map(|child| bluegum::Builder::render_with_state(child, state))
                          .collect::<Vec<bluegum::Builder>>(),
                  );
              };
          };
      }
  }
