Macro cargo_component_macro::generate
source · generate!() { /* proc-macro */ }Expand description
Used to generate bindings for a WebAssembly component.
By default, all world exports are expected to be implemented
on a type named Component where the bindings! macro
is invoked.
Additionally, all resource exports are expected to be
implemented on a type named <ResourceName>.
For example, a resource named file would be implemented
on a type named File in the same scope as the generate!
macro invocation.
Options
The macro accepts the following options:
implementor: The name of the type to implement world exports on.resources: A map of resource names to resource implementor types.ownership: The ownership model to use for resources.additional_derives: Additional derive macro attributes to add to generated types
Examples
Using the default implementor names:
ⓘ
cargo_component_bindings::generate!()Specifying a custom implementor type named MyComponent:
ⓘ
cargo_component_bindings::generate!({
implementor: MyComponent,
})Specifying a custom resource implementor type named MyResource:
ⓘ
cargo_component_bindings::generate!({
resources: {
"my:package/iface/res": MyResource,
}
})Specifying the borrowing-duplicate-if-necessary ownership model
for resources:
ⓘ
cargo_component_bindings::generate!({
ownership: "borrowing-duplicate-if-necessary"
})