Skip to main content

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