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