Skip to main content

qubit_codec/transcode/
transcode_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//! Semantic marker trait for buffered encoders.
9
10use super::{
11    TranscodeEncodeError,
12    Transcoder,
13};
14
15/// Encodes logical values into encoded units over caller-provided buffers.
16///
17/// `TranscodeEncoder` refines [`Transcoder`] for implementations whose
18/// input is the logical value stream and whose output is the encoded unit
19/// stream. The trait adds no methods; it exists to make generic bounds
20/// distinguish encoding direction from decoding and unit-to-unit conversion.
21///
22/// The word "buffered" describes the caller-managed buffer and progress model.
23/// It does not require the implementor to own an internal buffer. An encoder
24/// may retain consumed input internally, but [`Transcoder::transcode`] must
25/// consume every visible input value before returning
26/// [`crate::TranscodeStatus::Complete`] and must never return
27/// [`crate::TranscodeStatus::NeedInput`]. It returns
28/// [`crate::TranscodeStatus::NeedOutput`] when more output capacity is needed;
29/// [`Transcoder::finish`] emits any retained output after the caller has
30/// supplied the complete logical input stream.
31pub trait TranscodeEncoder:
32    Transcoder<
33    Error = TranscodeEncodeError<
34        Self::EncodeError,
35        <Self as Transcoder>::Input,
36    >,
37>
38{
39    /// Domain error type produced by encode internals.
40    type EncodeError;
41}