Skip to main content

qubit_codec/
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//! Decoder trait.
11
12/// Decodes a borrowed input value into another representation.
13pub trait Decoder<Input: ?Sized> {
14    /// Decoded output type.
15    type Output;
16    /// Decoding error type.
17    type Error;
18
19    /// Decodes `input`.
20    ///
21    /// # Parameters
22    /// - `input`: Source value to decode.
23    ///
24    /// # Returns
25    /// Decoded output.
26    ///
27    /// # Errors
28    /// Returns an error when the input is malformed or unsupported by the codec.
29    fn decode(&self, input: &Input) -> Result<Self::Output, Self::Error>;
30}