kacrab_protocol/primitives/
error.rs1#[derive(Debug, thiserror::Error)]
10#[error("primitive decode failed")]
11#[non_exhaustive]
12pub struct PrimitiveError {
13 #[source]
15 pub kind: PrimitiveErrorKind,
16}
17
18impl PrimitiveError {
19 #[must_use]
21 pub const fn new(kind: PrimitiveErrorKind) -> Self {
22 Self { kind }
23 }
24}
25
26impl From<PrimitiveErrorKind> for PrimitiveError {
27 fn from(kind: PrimitiveErrorKind) -> Self {
28 Self::new(kind)
29 }
30}
31
32#[derive(Debug, thiserror::Error)]
34#[expect(
35 variant_size_differences,
36 reason = "InsufficientData carries usize×2 context; InvalidVarint a single u8. Boxing the \
37 larger variant would slow the hot path for negligible memory savings on a \
38 short-lived error."
39)]
40#[non_exhaustive]
41pub enum PrimitiveErrorKind {
42 #[error("insufficient data: needed {needed} bytes, only {available} available")]
44 InsufficientData {
45 needed: usize,
47 available: usize,
49 },
50
51 #[error("invalid varint: continuation bit set past byte {max_bytes}")]
53 InvalidVarint {
54 max_bytes: u8,
56 },
57
58 #[error("compact length {length} exceeds the i32 maximum")]
60 LengthOutOfRange {
61 length: u32,
63 },
64}