qubit_codec/transcode/encode_outcome.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//! Outcome of one buffered encode value attempt.
9
10use core::num::NonZeroUsize;
11
12/// Outcome returned by encode-side per-value hooks.
13///
14/// This is deliberately smaller than [`crate::TranscodeProgress`]. It only
15/// describes what happened to the current input value; the encode engine owns
16/// input/output cursor updates and progress construction.
17#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
18pub enum EncodeOutcome {
19 /// The current input value was consumed.
20 Consumed {
21 /// Output units written for this value.
22 written: usize,
23 },
24
25 /// The current input value was not consumed because output is too small.
26 NeedOutput {
27 /// Total output units required from the current output cursor.
28 required: NonZeroUsize,
29 },
30}
31
32impl EncodeOutcome {
33 /// Creates an outcome for a consumed input value.
34 #[inline(always)]
35 #[must_use]
36 pub const fn consumed(written: usize) -> Self {
37 Self::Consumed { written }
38 }
39
40 /// Creates an outcome for insufficient output capacity.
41 #[inline(always)]
42 #[must_use]
43 pub const fn need_output(required: NonZeroUsize) -> Self {
44 Self::NeedOutput { required }
45 }
46}