.capnp protocols can use explicit bindings:
capnp id, then create schema/user.capnp:
build.rs; the capnp compiler must be installed locally:
Generated accessors are found using Rust field names by default.
#[model(capnp_name = "fullName")] selects a protocol field independently; #[model(capnp_skip, default = "local")] retains an internal model field. JSON aliases, flattening, extra fields, and exclusion control the JSON representation. The .capnp file determines the native field layout.
parse_capnp performs model normalization and synchronous validation; dump_capnp revalidates the current object. Asynchronous models use parse_capnp_async/dump_capnp_async and their packed equivalents. parse_capnp_with_options accepts the official ReaderOptions for traversal and nesting limits; single-message entry points reject trailing data. from_capnp_reader accepts an officially generated Reader, and to_capnp_message returns a message Builder for use with the official API. read_capnp/write_capnp are low-level composition interfaces; use the public parsing and output entry points above for full validation.
Native bindings require concrete, owned models. Constructing a Rust model allocates Strings and collections; keep an official Reader when direct message-memory access is needed. Protocol defaults follow Cap’n Proto semantics. Optional values use explicit unions, and capnp_skip fields use model defaults. JSON before callbacks still receive a field Value, and capnp_text mappings for dates and Decimal reuse scalar conversion rules.
See fixtures/capnp for a complete schema, officially generated bindings, and an executable example. Run the example and official CLI interoperability tests: