Expand description
WIT generation for the Fidius WASM backend (FIDIUS-I-0023).
Maps the Rust types in a #[plugin_interface] to WIT, per
docs/explanation/wasm-component-abi.md. Primitives, String, Vec<T>,
Option<T>, and Result<T, PluginError> map directly; user types that
carry #[derive(WitType)] map to WIT records (structs) and variants
(enums), referenced by their kebab-case name.
This is a plain library (not a proc-macro), so fidius-macro, the build.rs
helper, and the fidius wit CLI can all share one implementation.
Structs§
- Generated
- The product of generating from a plugin crate’s source.
- WitMethod
- One method projected to WIT (already-mapped strings).
Functions§
- contains_
user_ type - Whether
tyis, or contains (throughVec/Option/Box), a user type inknown. Public so the macro can classify args/returns. - conv_
expr - Conversion expression for a field/payload
accessof typety. Identity (move) when the type holds no user type (generated and author types are then identical); otherwise.into()(user type), or amap/into_iter().map()recursing throughOption/Vec. Symmetric — works generated→author and author→generated, sinceFromis generated both ways. Public so the macro’s adapter reuses the exact same boundary conversions. - enum_
to_ wit - Render a Rust enum to WIT: a
variant <name> { ... }plus any synthetic records for struct-shaped cases. Returns(synthetic_records, variant). - generate
- Generate WIT + conversions from a crate’s source string (
lib.rs). Inline modules (mod m { .. }) are walked; externalmod m;files cannot be read from a bare string — usegenerate_from_path(thebuild.rshelper does). - generate_
from_ path - Like
generate, but readslib_rsand follows externalmod m;files (resolvingm.rs/m/mod.rs), so#[derive(WitType)]types and the#[plugin_interface]trait may live in submodules. - is_
wit_ keyword - Whether
ident(an already-kebab-cased WIT identifier) is a reserved WIT keyword and so must be%-escaped when written into WIT source. - render_
wit - Convenience: render a WIT document with no user type defs (the primitives-only
form
fidius-macroemits inline today). - render_
wit_ full - Render a complete
.witdocument: package + interface (theplugin-errorrecord, any usertype_defs(records/variants), the funcs, and thefidius-interface-hashcarrier) + the<iface>-pluginworld.type_defsare pre-rendered (seestruct_to_record/ [enum_to_variant]). - result_
ok_ type - Extract the
TfromResult<T, _>, iftyis aResult. - return_
to_ wit - Primitive/std-only return mapping (no user types).
- return_
to_ wit_ with - Map a method’s return type to an optional WIT return, with user types in
known.Result<T, PluginError>→result<T, plugin-error>(orresult<_, plugin-error>forT = ());()/none → no return. - rust_
type_ to_ wit - Primitive/std-only mapping (no user types) — the form
fidius-macrouses for the descriptor/method tables. - stream_
item_ type - If
tyisfidius::Stream<T>(final path segmentStream, exactly one type argument), returnT. The server-streaming marker (FIDIUS-I-0026, D4). Public so the macro’s WASM adapter shares the same detection. - struct_
to_ record - Render a
record <name> { ... }WIT block from a Rust struct (named fields only). Field types are mapped withknownso they may reference other user types. - to_
kebab_ case - Convert a Rust identifier (CamelCase or snake_case) to kebab-case, the WIT
naming convention.
BytePipe→byte-pipe,echo_bytes→echo-bytes. - wit_
ident - Escape a generated WIT identifier so it is valid even when it collides with a
WIT keyword:
stream→%stream,row→row. - wit_
type_ with - Map a Rust argument/return type to its WIT spelling, where
knownholds the Rust identifiers of#[derive(WitType)]user types (mapped to their kebab-case record/variant name). ReturnsErr(msg)for unsupported types.