---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_with_generics"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST)]
  pub struct Generic<T> {
      field: NodeId<T>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct Generic {
      /// 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) field: crate::NodeId,
  }
  impl Generic {
      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 generic_field {}
  #[allow(unused)]
  impl Generic {
      ///Returns the `field` field
      pub fn get_field<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast T> {
          {
              let field = &self.field;
              ast.node(*field).and_then(|node| T::from_node(node))
          }
      }
      ///Returns the NodeId for the `field` field
      pub fn get_field_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let field = &self.field;
              *field
          }
      }
  }
  #[allow(unused)]
  impl<'ast> Generic {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for Generic {
      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) }, "Generic"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for Generic {
      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) }, "Generic"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for Generic {
      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)
                  },
                  &"Generic",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for Generic {
      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)
                  },
                  &"Generic",
              ),
          );
          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 field = &self.field;
                  b.add_node_with_state(state, stringify!(field), field);
              };
          };
      }
  }
