Skip to main content

Crate lattice_plugin_sdk_derive

Crate lattice_plugin_sdk_derive 

Source
Expand description

#[derive(PluginEvent)] — the guest-side derive for plugin-defined events (PH7.8b.3). The companion proc-macro crate to lattice-plugin-sdk (the serde/serde_derive split: a proc-macro crate cannot also export a normal library, so the runtime trait lives in lattice-plugin-sdk, which re-exports this derive).

The derive is WIT-agnostic (PH7.8b.3 approach A): it generates a PluginEvent impl over the opaque MessagePack wire and touches no plugin-host bindings. A plugin emits with its own generated host-services emit-event using the derived NAME + encode(); the derive only supplies the type-safe encode/decode + the name/doc constants.

Generated for #[derive(PluginEvent)] struct Foo { .. }:

  • NAME — from #[event(name = "...")], else the type name kebab-cased.
  • DOC — the struct’s /// doc-comment (the doc-comment IS the event doc, the PI.4 “doc from doc comments” principle applied to events).
  • encode / decode — MessagePack via lattice-plugin-sdk’s private helpers, so the consumer deps only the SDK (not rmp-serde directly).

The consumer must also #[derive(serde::Serialize, serde::Deserialize)] — the encode/decode bodies require it. Generated code references ::lattice_plugin_sdk, so the consumer must depend on lattice-plugin-sdk (which uses extern crate self as lattice_plugin_sdk; so the paths resolve in its own tests).

Derive Macros§

ConfigShape
Derive ConfigShape for a struct with named fields, or for an enum whose variants are all unit.
PluginEvent
Derive PluginEvent for a serde-serializable struct. See the crate docs for the generated items and the #[event(name = "...")] / doc-comment inputs.
PluginOption
Derive PluginOption for a newtype struct over bool / i64 / String (PH7.10b) — the guest-side ergonomic layer over the config.register-option wire. Like PluginEvent, it is WIT-agnostic: it generates only metadata constants + the value type; the plugin makes the register-option / get-option WIT calls itself using them.