Skip to main content

ic_wire/
lib.rs

1//! Bounded Postcard contracts for controlled IC endpoints.
2//!
3//! Transport, authentication, semantic validation and replay policy belong to
4//! consumers. See the runtime guide for maintained wire rules.
5#![no_std]
6#![doc = include_str!("../README.md")]
7extern crate alloc;
8mod bounded;
9mod contract;
10mod float;
11pub mod schema;
12mod shape;
13/// Optional host-side TypeScript generation; never required by a canister.
14#[cfg(feature = "typescript")]
15pub mod typescript;
16pub use bounded::{Bytes, List, Text};
17pub use contract::{
18    Method, RequestBytes, ResponseBytes, decode_request, decode_response, encode_request,
19    encode_response, encoded_request_len, encoded_response_len,
20};
21pub use float::{FiniteF32, FiniteF64};
22pub use ic_wire_derive::Wire;
23pub use shape::{Limits, Shape, Wire};
24
25/// Implementation dependencies used by generated contracts.
26#[doc(hidden)]
27pub mod __private {
28    pub use serde;
29}
30
31/// Typed codec/admission failure, distinct from transport and application errors.
32#[derive(Clone, Copy, Debug, Eq, PartialEq)]
33pub enum Error {
34    /// Wire, collection or text allowance exceeded.
35    Limit,
36    /// The declared schema exceeds the method's resource allowances.
37    SchemaLimit,
38    /// Allocation failed within an admitted allowance.
39    Allocation,
40    /// Invalid or truncated Postcard representation.
41    Malformed,
42    /// Bytes remain after the expected value.
43    Trailing,
44    /// A valid value used a noncanonical representation.
45    Noncanonical,
46    /// Envelope marker, method identity or direction differs.
47    Identity,
48}
49impl core::fmt::Display for Error {
50    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51        write!(f, "wire {self:?}")
52    }
53}
54impl core::error::Error for Error {}