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