Skip to main content

ic_wire/schema/
mod.rs

1//! Static metadata for projections of the maintained wire contract.
2
3/// A field in ascending wire-ID order.
4#[derive(Clone, Copy, Debug)]
5pub struct Field {
6    /// Rust field name, without a raw-identifier prefix.
7    pub name: &'static str,
8    /// Explicit field identity; not a transmitted tag.
9    pub id: u32,
10    /// Field encoding and bounds.
11    pub value: &'static Schema,
12}
13/// One explicitly tagged enum alternative.
14#[derive(Clone, Copy, Debug)]
15pub struct Variant {
16    /// Source variant name.
17    pub name: &'static str,
18    /// Transmitted Postcard u32 tag.
19    pub id: u32,
20    /// Unit or the single payload's encoding.
21    pub value: &'static Schema,
22}
23/// Finite type metadata, emitted by Wire derives and bounded built-ins.
24/// Manual Wire implementations default to Opaque and cannot generate bindings.
25#[derive(Clone, Copy, Debug)]
26#[non_exhaustive]
27pub enum Schema {
28    /// No trustworthy generated projection is available.
29    Opaque,
30    /// Zero-byte unit.
31    Unit,
32    /// A strict boolean byte.
33    Bool,
34    /// Unsigned integer width in bits.
35    Unsigned(u8),
36    /// Signed integer width in bits (i8 is a raw two's-complement byte).
37    Signed(u8),
38    /// Finite IEEE-754 width in bits (32 or 64); preserves signed zero.
39    Float(u8),
40    /// Bytes with a maximum length.
41    Bytes(usize),
42    /// UTF-8 text with a maximum byte length.
43    Text(usize),
44    /// Element schema and maximum count.
45    List(&'static Schema, usize),
46    /// Element schema and exact count, without a length prefix.
47    Array(&'static Schema, usize),
48    /// Optional value, with explicit None/Some tags.
49    Option(&'static Schema),
50    /// Ok and Err payloads respectively.
51    Result(&'static Schema, &'static Schema),
52    /// Fields in their explicit wire order.
53    Record(&'static [Field]),
54    /// Alternatives selected by explicit transmitted IDs.
55    Enum(&'static [Variant]),
56}