Skip to main content

qubit_io/codec/
leb128_decode_error.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9******************************************************************************/
10use thiserror::Error;
11
12use crate::Leb128DecodeErrorKind;
13
14/// Error reported while decoding a LEB128 integer from a byte buffer.
15#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
16#[error("{kind}")]
17pub struct Leb128DecodeError {
18    kind: Leb128DecodeErrorKind,
19    index: usize,
20}
21
22impl Leb128DecodeError {
23    /// Creates a LEB128 decoding error.
24    ///
25    /// # Parameters
26    ///
27    /// - `kind`: Failure category.
28    /// - `index`: Absolute byte index at which the failure was detected.
29    ///
30    /// # Returns
31    ///
32    /// Returns a decoding error carrying the supplied context.
33    #[inline]
34    pub const fn new(kind: Leb128DecodeErrorKind, index: usize) -> Self {
35        Self { kind, index }
36    }
37
38    /// Returns the decoding error kind.
39    #[must_use]
40    #[inline]
41    pub const fn kind(self) -> Leb128DecodeErrorKind {
42        self.kind
43    }
44
45    /// Returns the absolute byte index associated with this error.
46    #[must_use]
47    #[inline]
48    pub const fn index(self) -> usize {
49        self.index
50    }
51}