Skip to main content

ic_wire/
error.rs

1/// Wire failure categories, independent of transport and application errors.
2///
3/// Allocation is reserved for fallible codec-owned output allocation; consumer
4/// deserialization can allocate outside the codec's control.
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub enum Error {
7    /// A wire, collection, traversal or output allowance was exceeded.
8    Limit,
9    /// Allocation failed within an admitted allowance.
10    Allocation,
11    /// The representation is invalid or truncated.
12    Malformed,
13    /// Input remains after the expected value.
14    Trailing,
15    /// The envelope marker, method identity or direction differs.
16    Identity,
17}
18
19impl core::fmt::Display for Error {
20    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21        formatter.write_str(match self {
22            Self::Limit => "wire limit",
23            Self::Allocation => "wire allocation",
24            Self::Malformed => "wire malformed",
25            Self::Trailing => "wire trailing",
26            Self::Identity => "wire identity",
27        })
28    }
29}
30
31impl core::error::Error for Error {}