Skip to main content

qubit_codec/transcode/engine/
transcode_decode_engine_error.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Domain error reported by buffered decode engines.
9
10use thiserror::Error;
11
12use crate::CodecDecodeError;
13
14/// Error reported by [`crate::TranscodeDecodeEngine`].
15///
16/// This type keeps codec lifecycle failures separate from policy hook failures.
17/// Facade adapters may flatten both branches when they intentionally use the
18/// same public domain error type for codec and hook failures.
19///
20/// # Type Parameters
21///
22/// - `C`: Codec decode error type.
23/// - `H`: Decode hook error type.
24#[derive(Clone, Copy, Debug, Eq, Error, Hash, PartialEq)]
25pub enum TranscodeDecodeEngineError<C, H> {
26    /// The wrapped codec failed during decode lifecycle work.
27    #[error("{0}")]
28    Codec(#[source] CodecDecodeError<C>),
29
30    /// The decode policy hook rejected or failed input.
31    #[error("{0}")]
32    Hook(#[source] H),
33}
34
35impl<C, H> TranscodeDecodeEngineError<C, H> {
36    /// Creates an error from a codec lifecycle failure.
37    ///
38    /// # Parameters
39    ///
40    /// - `error`: Codec decode adapter error.
41    ///
42    /// # Returns
43    ///
44    /// Returns a decode-engine codec error.
45    #[inline(always)]
46    #[must_use]
47    pub const fn codec(error: CodecDecodeError<C>) -> Self {
48        Self::Codec(error)
49    }
50
51    /// Creates an error from a hook failure.
52    ///
53    /// # Parameters
54    ///
55    /// - `error`: Hook error.
56    ///
57    /// # Returns
58    ///
59    /// Returns a decode-engine hook error.
60    #[inline(always)]
61    #[must_use]
62    pub const fn hook(error: H) -> Self {
63        Self::Hook(error)
64    }
65}