Skip to main content

functions

Macro functions 

Source
macro_rules! functions {
    (
        $(
            {
                name: $name:expr,
                $(version: $version:expr,)?
                description: $description:expr,
                method: $method:ident,
                $(visibility: $visibility:ident,)?
                $(permission: $permission:expr,)?
                $(role: $role:expr,)?
                $(admin: {
                    $(visible: $admin_visible:expr,)?
                    $(roles: $admin_roles:expr,)?
                    $(label: $admin_label:expr,)?
                    $(group: $admin_group:expr,)?
                    $(description: $admin_description:expr,)?
                    $(confirm: $admin_confirm:expr,)?
                    $(run_label: $admin_run_label:expr,)?
                    $(order: $admin_order:expr,)?
                },)?
                handler: $handler:path
                $(,)?
            }
        ),+
        $(,)?
    ) => { ... };
}
Expand description

Define and export several apiplant functions from one library.

Each entry is an independent function with its own name, manifest and handler — there is no shared dispatcher and no matching inside a handler. This is how one crate provides a set of related endpoints, or a resource’s whole set of lifecycle hooks:

apiplant_function::functions! {
    {
        name: "post_before_create",
        description: "Validates a post before it is stored.",
        method: Post,
        visibility: Private,
        handler: post_before_create,
    },
    {
        name: "post_after_create",
        description: "Records a newly created post.",
        method: Post,
        visibility: Private,
        handler: post_after_create,
    },
}

Then, in models/post.toml:

[hooks]
before_create = "post_before_create"
after_create  = "post_after_create"

Every entry takes the same fields as function!, and each handler keeps its own inferred Config/Input/Output types. Names must be unique within a library; the host rejects duplicates at load time.