Skip to main content

qubit_codec/value/
value_encoder.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 encoder trait.
11
12/// Encodes 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 encoding and [`crate::BufferedTranscoder`] for batch conversion over
16/// caller-provided buffers.
17pub trait ValueEncoder<Input: ?Sized> {
18    /// Encoded output type.
19    type Output;
20    /// Encoding error type.
21    type Error;
22
23    /// Encodes `input`.
24    ///
25    /// # Parameters
26    /// - `input`: Source value to encode.
27    ///
28    /// # Returns
29    /// Encoded output.
30    ///
31    /// # Errors
32    /// Returns an error when the codec cannot represent the supplied input.
33    fn encode(&self, input: &Input) -> Result<Self::Output, Self::Error>;
34}