std/derives
import std/derives to use it. Source: src/std/derives.iyi at v0.18.0.
A derive is an exported macro that takes one argument: the declaration it is attached to. It reads that declaration's name and its fields, each field with the type it was written as. It never sees a type it was not given, and it never runs in the consumer.
describedmacro
Renders a value as its type name and its fields. One macro, any declaration: the fields come from whichever type the derive is written in.
pub macro described(declaration)shownmacro
The question II.4 is about: whether a field's type implements a trait. Only the fields that answer yes are rendered, and each one is rendered by calling the trait's method. A field whose type this macro cannot see answers nil.
pub macro shown(declaration)Namestruct
A type this module exports, implementing a trait this module exports. A derive in another module gets to ask about both, and both arrive from this module's .iyimod when its source is gone.
pub struct Name
def initialize(text : String)
endShowtrait
pub trait Show
abstract def show : String
endShow for Nameimpl
impl Show for Name
def show : String
end
Derives, as a library module (SPEC.md R-5, II.4).