IC Wire derive
Rust declarations for IC Wire. Use the coordinated re-export.
[]
= { = "0.31.2", = ["derive"] }
= { = "1", = ["derive"] }
The fixed mode describes a supported Serde layout for the validated schema graph.
Ordinary enum declarations also use schema projection for their Serde layout.
Unsupported attributes fail explicitly. Fixed layouts support generics, borrowed
fields, symmetric field and variant renames, standard serde_bytes and qualified
IC Wire packed adapters. Renamed dependencies use #[wire(crate = "dependency_name")].
The same derive works on native and Wasm DTOs. It emits the same schema trait implementation on both targets.
Use #[derive(ic_wire::Wire)] on the request and reply types of an
ic_wire::evolution::Method. Enable evolution-derive for Rust or derive to
also generate client metadata. Add optional fields to the same declaration with
#[wire(id = N)] and a stable, unused ID. Untagged fields form the positional
core. Every method root encodes an extension block, including the first release
with no tagged fields. Tuple structs use the same derive and assign each
optional tail element its one-based tuple position. The derive also projects
nested Wire structs and tuple structs through supported containers. Add a
required named field with #[wire(id = N, required)] and its non-optional
type. Check new required IDs against each shipped request and reply schema.
Choose #[wire(fixed)] when a nested subtree uses its ordinary Serde layout.
Use Evolve on the field or case declarations when projecting explicit nested
envelopes.
use ;
Use the generated encode_extensions and decode_extensions methods to
prepare and project the final block. State::encode_open accepts an
Option<&State>, and State::decode_open returns absence for an unknown case.
The helpers use the containing Wire operation's admission context. For a
required open value beneath an explicitly recovering branch, use
OpenSlot<'a, State, true> with the generated required-case helpers and a
RecoverSlot enclosing the branch. Use decode_extensions_in to recover
the enclosing branch when a required extension is missing. Pass a tuple with
one projector per declared field, ordered by ascending ID. A Serde leaf uses
|value, _| Ok(value). A field with nested envelopes projects every known
descendant in the supplied field scope before returning the validated value.
The helper completes those checks before it can mark a missing required field.
A tuple struct can declare its final ExtensionSlot with #[wire(extensions)]
as well. The tail IDs identify one-based positions. A tuple with one fixed
slot starts its optional tail at ID 2. Assign consecutive IDs and append
new optional slots after the existing ones. Schema generation validates this
sequence. Earlier tuple writers can omit the new slots, while earlier readers
skip them and preserve the enclosing alignment. Declare the tail carrier from
the first version, including when the tail is empty.
Requires Rust 1.100.0. The derive and runtime crate are released together.
See IC Wire for usage and qualification.
Licensed under the included Apache License 2.0 (LICENSE.md).