Module compiler

macro

Macros are Coil functions that run at compile time and return code. A derive receives a TypeDecl, an attribute macro an FnDecl or TypeDecl, and a function-style macro (name!(…)) its arguments as Expr. Each returns Code, usually built with a quote block. See Macros and the macros tutorial.

Written in Coil and shipped inside the compiler.

Import what you use (use path::* is not allowed):

use macro::{Code, Ident};

Types#

NameDescription
CodeGenerated coil source: declarations, an expression, statements or a type.
IdentA name as written in source.
ExprA function-style macro argument as written: f(1), a + b, "text".
TypeRefA type annotation as written (not resolved): Vec<int>, json::Value.
AttrArgOne key = value (or positional value, with key == "") attribute argument.
Attr#[name(args)] on a declaration, field or variant.
FieldA class field, or a field of a record enum variant.
VariantOne enum variant.
TypeDeclA class or enum declaration handed to a derive or attribute macro.
ParamOne function parameter.
FnDeclA function or method handed to an attribute macro.
ReaderReads a macro call’s input: length-prefixed fields (<len>:<bytes>, lists as a count then their items) in constructor order, written by the compiler (macros::encode).

Functions#

NameDescription
joinJoin fragments with sep (the lowering of $(xs) sep *).
litA string literal: lit("a\"b") splices as "a\"b".
lit_intAn integer literal.
rawRaw source, spliced as is.
concatCombine several generated item lists.
identA name, for splicing generated identifiers: ${ident("to_" + n)}.
decimalA decimal integer the compiler wrote (- then digits, in range).
attr_indexIndex of the attribute called name, or -1.
attr_value#[attr(key = "value")] from an attribute list, or fallback.
↑ ↓ navigate ↵ open