Skip to main content

FunctionConfig

Derive Macro FunctionConfig 

Source
#[derive(FunctionConfig)]
{
    // Attributes available to this derive:
    #[config]
    #[output]
}
Expand description

Derives FunctionConfig for a function’s typed configuration, and ConfigField, so a derived config nests inside another.

It applies to a struct with named fields. Each field is compiled from the key of its name through the field type’s ConfigField implementation, every issue at its own path, unknown keys first.

AttributeOnMeaning
#[config(rename = "k")]fieldThe JSON key; the default is the field’s name
#[config(default = <literal>)]fieldA string, integer, float or bool, compiled through the field’s type when the key is absent
#[config(default_json = "<json>")]fieldAny JSON default, as text; text that is not JSON is a compile error
#[config(serde)]fieldRead with serde_json; an error is INPUT_PARSE, and an absent key is read from null. Resolved as it serializes, so the type is Serialize too
#[config(records)]fieldThe engine records the field’s result; inherited by everything below it
#[output(default = "p")]outputThe default when the key is absent or null
#[output(primary)]outputRequired on exactly one output when there are several
#[config(check = path)]structfn(&Self, &mut CompileCx<'_>), called only when every field compiled

A field is an output when it carries #[output(...)], or its type’s last path segment is Output, or it is an Option of such a type. A field’s doc comment is its description.

The primary output, the one marked or the only one, is what FunctionConfig::primary_output returns, so its type is Output or Option<Output>; any other is refused.

FunctionConfig::resolve gives every field with a value, set by the input or by its default, keyed by its key, in declaration order, each through its type’s ConfigField::resolve, and a serde field as it serializes; an Option left unset is absent.