--serdeRust emitterAdds plain #[derive(Serialize, Deserialize)] using Rust field names, plus private helpers for [T; N] with N > 32.
Inspect exactly how every supported WIT type compiles into Rust, TypeScript, Python, Go, Java 21, C# 12, Protobuf, JSON Schema, and checked glue, and how schema edits behave across wire lockfiles, 4-view diffs, and generated version adapters.
Every row reflects the normative emitter specification. Unsupported constructs (resources, handles, tuples, futures, streams, async functions, and unsupported map keys) are rejected up front by witforge check.
Scalar WIT types keep exact integer widths and signedness in Rust, use explicit proto3 presence when required, and enforce narrow ranges and Unicode scalar validity in checked glue.
| WIT construct | Plain Rust | Protobuf (proto3) | JSON Schema | Checked glue and notes |
|---|---|---|---|---|
bool | bool | optional bool (required) / bool in flags | {"type":"boolean"} | Required record fields reject absent proto optional with GlueError::MissingField. |
u8, u16, u32 | u8, u16, u32 | optional uint32 | integer with exact min/max (0..255, 0..65535, 0..4294967295) | Glue range-checks u8 and u16 from uint32 (GlueError::IntegerOutOfRange). |
u64 | u64 | optional uint64 | integer (0..18446744073709551615) | Proto3-JSON encodes u64 as decimal strings; Rust Serde emits exact JSON numbers. |
s8, s16, s32 | i8, i16, i32 | optional sint32 | integer with exact signed min/max | ZigZag-encoded sint32; glue range-checks s8 and s16 into i8/i16 (GlueError::IntegerOutOfRange). |
s64 | i64 | optional sint64 | integer (-9223372036854775808..9223372036854775807) | ZigZag-encoded sint64; proto3-JSON encodes s64 as decimal strings. |
f32, f64 | f32, f64 | optional float / optional double | number (f32 bounded to finite IEEE-754 range) | Types containing floats omit Eq and Hash even when --eq-hash is enabled. |
char | char | optional uint32 | {"type":"string","minLength":1,"maxLength":1} | Glue validates Unicode scalar values via char::from_u32 (GlueError::InvalidChar). |
string | ::std::string::String (::alloc::string::String under --no-std) | optional string | {"type":"string"} | UTF-8 string; presence-checked when required. |
Named records, variants, enums, flags, options, and all four WIT result shapes map into exhaustive Rust types, locked protobuf declarations, and closed JSON Schema definitions.
| WIT construct | Plain Rust | Protobuf (proto3) | JSON Schema | Checked glue and notes |
|---|---|---|---|---|
record | pub struct with pub fields | message <Interface><Type> | closed object (all properties required, additionalProperties: false) | Field numbers locked in wire.lock; required fields enforce presence in glue. |
variant | pub enum with unit and tuple variants | message with oneof witforge_value (Empty for payload-less cases) | oneOf single-key closed objects (null for payload-less cases) | Unset oneof fails decode with GlueError::UnknownCase. |
enum | pub enum (unit variants) | enum with <ENUM>_UNSPECIFIED = 0 and locked case numbers | {"type":"string","enum":[...]} (WIT kebab-case spelling) | Closed enum: 0 and unknown values fail with GlueError::UnknownEnumValue. |
flags | pub struct of pub bool fields | message of bool fields (locked field numbers) | closed object of required boolean properties | Absent proto3 bool decodes as false; adding or removing a flag stays binary decode compatible. |
option<T> | ::std::option::Option<T> (::core::option::Option<T> under --no-std) | optional T, message presence, WitforgeListOf/MapOf wrapper, or WitforgeOptionOf wrapper when nested | anyOf: [schema(T), {"type":"null"}] (property remains required) | Invalid or unset option wrapper oneof fails decode with GlueError::InvalidState. |
result<T, E> (all 4 forms) | ::std::result::Result<T, E> (::core under --no-std; () for omitted ok/err) | message with oneof value { ok = 1; err = 2; } (Empty when omitted) | closed single-key object with "ok" or "err" (null when omitted) | Unset oneof fails decode with GlueError::UnknownCase. |
Byte lists, generic lists, fixed-length arrays, and primitive-keyed maps preserve deterministic ordering and explicit wire length and presence semantics.
| WIT construct | Plain Rust | Protobuf (proto3) | JSON Schema | Checked glue and notes |
|---|---|---|---|---|
list<u8> (or byte alias) | ::std::vec::Vec<u8> (::alloc::vec::Vec<u8> under --no-std) | optional bytes (when required or optional) | array of 0..=255 integers (not base64) | Required list<u8> uses optional bytes presence (MissingField if absent on the wire). |
list<T> | ::std::vec::Vec<T> (::alloc::vec::Vec<T> under --no-std) | repeated singular(T) (wrapped inside oneof/option) | {"type":"array","items":...} | Absent repeated field decodes as an empty Vec; nested lists use wrapper messages. |
list<T, N> (1 <= N <= 65536) | [T; N] (private Serde helper generated when N > 32) | optional bytes (for u8) or repeated singular(T) | array with minItems: N and maxItems: N | Glue verifies exact length N on decode (GlueError::InvalidLength). |
map<K, V> (K: bool, int, char, string) | ::std::collections::BTreeMap<K, V> (::alloc under --no-std) | map<proto_key(K), singular(V)> (WitforgeMapOf... wrapper in singular position) | object with additionalProperties + propertyNames constraints | Deterministic BTreeMap order; narrow int and char keys validated in glue. |
Standard deps/ packages and WIT type aliases stay deterministic across multi-version contract roots without duplicating type definitions.
| WIT construct | Plain Rust | Protobuf (proto3) | JSON Schema | Checked glue and notes |
|---|---|---|---|---|
type a = b and use aliases | pub type A = B; inside the declaring/using interface module | Inlined to the defining type (no extra message or lockfile key) | {"$ref":"#/definitions/..."} (or $defs in Draft 2020-12) | Byte-list aliases (type byte = u8; list<byte>) resolve to bytes/Vec<u8>. |
deps/ packages and worlds | witforge_deps::<ns>_<pkg> (major-scoped only when a dependency differs across live majors) + worlds.rs | <ns>.<pkg>.v<dep_major>.proto imported by root v<major>.proto | <ns>.<pkg>.v<dep_major>.schema.json referenced across files | Unused unsupported dependency items are pruned cleanly; witforge deps sync keeps minors aligned. |
Every polyglot emitter generates zero-dependency plain types plus bidirectional version adapters alongside a checked protobuf glue emitter verified against witforge conformance in CI. Inspect committed files under examples/polyglot.
Plain types depend only on each language's standard library. Checked protobuf glue pairs those plain types with the canonical protobuf runtime for each ecosystem.
| Language | Target baseline | CLI commands | Plain type shapes | Version adapters | Checked glue runtime |
|---|---|---|---|---|---|
| TypeScript | Strict ESM (NodeNext) | ts, ts-glue | readonly interfaces, as-const string enums, discriminated unions | convert.ts | @bufbuild/protobuf |
| Python | Python 3.11+ stdlib | py, py-glue | frozen dataclasses (slots=True), StrEnum, Protocol, py.typed | convert.py | google.protobuf (protoc --python_out) |
| Go | Go 1.22+ stdlib | go, go-glue | gofmt structs, Valid()/String() enums, sealed variant interfaces | convert/ | google.golang.org/protobuf (protoc-gen-go) |
| Java | Java 21+ stdlib | java, java-glue | defensive records, enums, sealed interface ... permits variants | Convert.java | com.google.protobuf (protoc --java_out) |
| C# | C# 12+ / .NET 8+ stdlib | csharp, csharp-glue | #nullable enable sealed records, value-equality lists, abstract record variants | Convert.cs | Google.Protobuf (protoc --csharp_out) |
Checked glue enforces exact narrow integer ranges, Unicode scalar values, required field presence, closed enums, and fixed lengths across both decode and encode boundaries.
| WIT type | TypeScript | Python 3.11+ | Go 1.22+ | Java 21+ | C# 12+ / .NET 8+ |
|---|---|---|---|---|---|
u8, u16, u32 | number | int | uint8, uint16, uint32 | int (unsigned range) | byte, ushort, uint |
s8, s16, s32 | number | int | int8, int16, int32 | byte, short, int | sbyte, short, int |
u64 / s64 | bigint | int | uint64 / int64 | long (unsigned 64-bit for u64) | ulong / long |
char | string (1 scalar) | str (1 scalar) | rune | int (Unicode scalar) | System.Text.Rune |
list<u8> / list<T> | Uint8Array / readonly T[] | bytes / tuple[T, ...] | []byte / []T | byte[] / List<T> | byte[] / IReadOnlyList<T> |
list<u8, N> / list<T, N> | Uint8Array / readonly T[] (len N) | bytes / tuple[T, ...] (len N) | [N]byte / [N]T | byte[] / List<T> (len N) | byte[] / IReadOnlyList<T> (len N) |
map<K, V> | ReadonlyMap<K, V> | Mapping[K, V] | map[K]V | Map<K, V> | IReadOnlyDictionary<K, V> |
option<T> | Option<T> | T | None (nested: Option[T]) | *T (nested: Option[T]) | Optional<T> | T? (nested: WitforgeOption<T>) |
result<T, E> | { tag: "ok"; value: T } | { tag: "err"; error: E } | Ok[T] | Err[E] | Result[T, E] | WitforgeResult<T, E> | WitforgeResult<T, E> |
Default plain types require zero external dependencies across all six languages. Enable Rust traits or no_std, Draft 2020-12 JSON Schema, protobuf language options, selective --only generation, conformance bundles, or opt-in plugins per project in witforge.toml or via CLI flags.
--serdeRust emitterAdds plain #[derive(Serialize, Deserialize)] using Rust field names, plus private helpers for [T; N] with N > 32.
--no-stdRust, convert.rs, glueReplaces ::std paths with ::core and ::alloc (including alloc::collections::BTreeMap and core::error::Error on Rust 1.88+).
--eq-hashRust emitterDerives Eq and Hash on every generated type that does not transitively contain f32 or f64.
--try-fromRust convert.rsEmits both borrowed TryFrom<&From> and owned TryFrom<From> impls in both directions for converted nominal types (records, variants, enums, flags).
--draft 2020-12JSON Schema emitterSwitches JSON Schema from Draft 7 (definitions) to Draft 2020-12 ($defs and native deprecated: true annotations).
--go-package / --java-package / --csharp-namespaceProtobuf emitterEmbeds derived Go, Java (with --java-multiple-files and --java-outer-classname), and C# protobuf file options without changing wire numbers.
--only <GEN[,GEN...]>witforge generateRuns or checks a validated subset of configured generators across rust, proto, schema, glue, doc, polyglot emitters, and opt-in plugins.
witforge conformanceCross-language bundleExports canonical WIT, .proto (with optional --polyglot-proto-options), and deterministic binary plus proto3-JSON vectors proving glue parity.
witforge plugin / --allow-pluginsThird-party emittersInvokes external witforge-gen-<name> binaries over bounded JSON-on-stdio (protocol_version = 1); explicit opt-in only, never run implicitly.
Released directories are immutable. A minor change lives in a new sibling directory that continues the prior wire.lock; a wire-breaking change starts a new major package.
witforge diff --check gates wire,source,api by default. Select binary decode gating explicitly with --check=wire,decode or [project.<name>.policy].
| Contract change (within one major) | wire | source | api | decode (binary) | Version adapter |
|---|---|---|---|---|---|
| Add option<T>, non-byte list<T>, or map<K, V> field | Compatible | Breaking | Breaking | Compatible | old -> new defaults (None / empty) |
| Add required list<u8> field | Compatible | Breaking | Breaking | Breaking (new<-old) | old -> new defaults to empty bytes; wire optional bytes rejects absence |
| Add required scalar, string, char, list<T, N>, or record field | Compatible | Breaking | Breaking | Breaking (new<-old) | Refused within a major (WF2002); omitted old -> new across majors |
| Add enum or variant case | Compatible | Breaking | Breaking | Breaking (old<-new) | new -> old returns UnknownCase for new case |
| Remove option<T>, non-byte list<T>, or map<K, V> field | Compatible (reserved) | Breaking | Breaking | Compatible | old -> new drops field; new -> old defaults |
| Remove required list<u8> field | Compatible (reserved) | Breaking | Breaking | Breaking (old<-new) | old -> new drops field; new -> old defaults to empty bytes |
| Remove required scalar, string, char, list<T, N>, or record field | Compatible (reserved) | Breaking | Breaking | Breaking (old<-new) | new -> old returns MissingMember |
| Remove enum or variant case | Compatible (reserved) | Breaking | Breaking | Breaking (new<-old) | old -> new returns UnknownCase for removed case |
| Add a flag member | Compatible | Breaking | Breaking | Compatible | old -> new sets false; new -> old drops |
| Remove a flag member | Compatible (reserved) | Breaking | Breaking | Compatible | old -> new drops; new -> old sets false |
| Add interface function | Compatible | Breaking | Breaking | Breaking (old<-new) | n/a (extends interface definition and method enum) |
| Renumber an existing member in wire.lock (same major) | Breaking | Compatible | Compatible | Breaking (both) | Refused by lockfile continuity check (WF1100) |
| Retype field, change type kind, or reuse a reserved tag on a new member | Breaking | Breaking | Breaking | Breaking (both) | Refused within a major (WF2002); omitted across majors (use new major) |
| Update docs or stability/deprecation metadata (in a new version) | Compatible | Compatible | Compatible | Compatible | Full round-trip (never edit a released version in place) |
Generated version adapters (convert.rs, convert.ts, convert.py, convert/, Convert.java, Convert.cs) convert plain values inside one process and default an added or removed list<u8> field to an empty byte sequence. On the wire, required list<u8> is proto3 optional bytes, so a reader rejects an omitted field from the opposite side with MissingField (reported as decode: BREAKING (new<-old) on addition and decode: BREAKING (old<-new) on removal). Strict proto3-JSON parsers also reject unknown fields unless configured to ignore them.
Read the full authoring rules, committed output walkthroughs, and cross-language decode requirements.