Skip to main content

qubit_codec/value/
value_decoder.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//! Owned-value decoder trait.
9
10/// Decodes a borrowed input value into an owned representation.
11///
12/// This trait is a convenience-layer API. Use [`crate::Codec`] for low-level
13/// single-value buffer decoding and [`crate::Transcoder`] for batch
14/// conversion over caller-provided buffers.
15pub trait ValueDecoder<Input: ?Sized> {
16    /// Decoded output type.
17    type Output;
18    /// Decoding error type.
19    type Error;
20
21    /// Decodes `input`.
22    ///
23    /// # Parameters
24    /// - `input`: Source value to decode.
25    ///
26    /// # Returns
27    /// Decoded output.
28    ///
29    /// # Errors
30    /// Returns an error when the input is malformed or unsupported by the
31    /// codec.
32    fn decode(&mut self, input: &Input) -> Result<Self::Output, Self::Error>;
33}