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