Class in macro compiler

TypeDecl

class TypeDecl
Import
use macro::{TypeDecl};
Source: compiler/src/prelude/macro.hy

A class or enum declaration handed to a derive or attribute macro.

Fields#

FieldTypeDescription
nameIdent
kindstring"class" or "enum".
genericsVec<Ident>
field_listVec<Field>
variant_listVec<Variant>
attrsVec<Attr>
reprstring#[repr(...)] backing ("int", …) or the inferred scalar backing, else "".
modulestringModule path the declaration lives in ("" for the entry file).
docsVec<string>
sourcestringThe declaration as written (an attribute macro’s own attribute removed).

Methods#

NameDescription
is_class
self_typeThe type as written in a signature: Name, or Name<T, U> for a generic type.
impl_headHead of an impl Trait for … for this type: Name, or for a generic type Name<T: bound, U: bound>, every type parameter bounded by bound ("Show", "Ord + Eq").
is_enum
fieldsClass fields (empty for an enum).
variantsEnum variants (empty for a class).
has_attr
attr_str

See also#

  • Code: Generated coil source: declarations, an expression, statements or a type.
  • Ident: A name as written in source.
  • Expr: A function-style macro argument as written: f(1), a + b, "text".
  • TypeRef: A type annotation as written (not resolved): Vec<int>, json::Value.
  • AttrArg: One key = value (or positional value, with key == "") attribute argument.
  • Attr: #[name(args)] on a declaration, field or variant.
  • Field: A class field, or a field of a record enum variant.
  • Variant: One enum variant.
↑ ↓ navigate ↵ open