Skip to main content

Crate fidius_wit

Crate fidius_wit 

Source
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 ty is, or contains (through Vec/Option/Box), a user type in known. Public so the macro can classify args/returns.
conv_expr
Conversion expression for a field/payload access of type ty. Identity (move) when the type holds no user type (generated and author types are then identical); otherwise .into() (user type), or a map/into_iter().map() recursing through Option/Vec. Symmetric — works generated→author and author→generated, since From is 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; external mod m; files cannot be read from a bare string — use generate_from_path (the build.rs helper does).
generate_from_path
Like generate, but reads lib_rs and follows external mod m; files (resolving m.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-macro emits inline today).
render_wit_full
Render a complete .wit document: package + interface (the plugin-error record, any user type_defs (records/variants), the funcs, and the fidius-interface-hash carrier) + the <iface>-plugin world. type_defs are pre-rendered (see struct_to_record / [enum_to_variant]).
result_ok_type
Extract the T from Result<T, _>, if ty is a Result.
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> (or result<_, plugin-error> for T = ()); ()/none → no return.
rust_type_to_wit
Primitive/std-only mapping (no user types) — the form fidius-macro uses for the descriptor/method tables.
stream_item_type
If ty is fidius::Stream<T> (final path segment Stream, exactly one type argument), return T. 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 with known so they may reference other user types.
to_kebab_case
Convert a Rust identifier (CamelCase or snake_case) to kebab-case, the WIT naming convention. BytePipebyte-pipe, echo_bytesecho-bytes.
wit_ident
Escape a generated WIT identifier so it is valid even when it collides with a WIT keyword: stream%stream, rowrow.
wit_type_with
Map a Rust argument/return type to its WIT spelling, where known holds the Rust identifiers of #[derive(WitType)] user types (mapped to their kebab-case record/variant name). Returns Err(msg) for unsupported types.