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