Skip to main content

qubit_codec_misc/
misc_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//! Shared codec error type.
9
10use core::num::NonZeroUsize;
11
12use qubit_codec::DecodeFailure;
13
14mod misc_codec_error;
15
16pub use self::misc_codec_error::MiscCodecError;
17
18/// Result alias returned by codec operations.
19///
20/// # Type Parameters
21///
22/// - `T`: Value produced by a successful codec operation.
23pub type MiscCodecResult<T> = Result<T, MiscCodecError>;
24
25/// Maps a malformed value to a decode failure with a known input width.
26///
27/// # Parameters
28///
29/// - `error`: Codec-specific error describing the malformed value.
30/// - `consumed`: Non-zero number of input units consumed by the malformed
31///   value.
32///
33/// # Returns
34///
35/// Returns an invalid decode failure that retains `error` and records
36/// `consumed` as the input width.
37#[inline]
38pub(crate) fn map_misc_decode_failure_with_consumed(
39    error: MiscCodecError,
40    consumed: NonZeroUsize,
41) -> DecodeFailure<MiscCodecError> {
42    DecodeFailure::invalid(error, consumed)
43}