qubit_codec/transcode/engine/transcode_encode_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 encode engines.
9
10use thiserror::Error;
11
12use crate::CodecEncodeError;
13
14/// Error reported by [`crate::TranscodeEncodeEngine`].
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 encode error type.
23/// - `H`: Encode hook error type.
24#[derive(Clone, Copy, Debug, Eq, Error, Hash, PartialEq)]
25pub enum TranscodeEncodeEngineError<C, H> {
26 /// The wrapped codec failed during encode lifecycle work.
27 #[error("{0}")]
28 Codec(#[source] CodecEncodeError<C>),
29
30 /// The encode policy hook rejected or failed a value.
31 #[error("{0}")]
32 Hook(#[source] H),
33}
34
35impl<C, H> TranscodeEncodeEngineError<C, H> {
36 /// Creates an error from a codec lifecycle failure.
37 ///
38 /// # Parameters
39 ///
40 /// - `error`: Codec encode adapter error.
41 ///
42 /// # Returns
43 ///
44 /// Returns an encode-engine codec error.
45 #[inline(always)]
46 #[must_use]
47 pub const fn codec(error: CodecEncodeError<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 an encode-engine hook error.
60 #[inline(always)]
61 #[must_use]
62 pub const fn hook(error: H) -> Self {
63 Self::Hook(error)
64 }
65}