qubit_codec/buffered/encode_plan.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//! One-value encoding plan used by buffered encoder hooks.
11
12/// Describes how much output capacity one encoded value needs before writing.
13///
14/// `EncodePlan` is produced by [`crate::BufferedEncodeHooks::prepare_encode`]
15/// and consumed by [`crate::BufferedEncodeHooks::write_encode`]. The capacity
16/// field is a safe upper bound required by the concrete writer, not necessarily
17/// the exact number of units that will be written.
18///
19/// # Type Parameters
20///
21/// - `A`: Concrete action interpreted by the encoder implementation.
22#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
23pub struct EncodePlan<A> {
24 /// Output units that must be writable before calling `write_encode`.
25 ///
26 /// Default codec-backed encoders usually use
27 /// [`crate::Codec::max_units_per_value`]. Domain-specific encoders may use
28 /// a tighter bound, such as a charset encoder using its exact encoded
29 /// length probe. A value of zero is valid for policies that consume input
30 /// without producing output.
31 pub max_output_units: usize,
32
33 /// Concrete write action interpreted by the encoder implementation.
34 pub action: A,
35}
36
37impl<A> EncodePlan<A> {
38 /// Creates an encoding plan.
39 ///
40 /// # Parameters
41 ///
42 /// - `max_output_units`: Output capacity required before writing.
43 /// - `action`: Concrete plan action for the encoder implementation.
44 ///
45 /// # Returns
46 ///
47 /// Returns an encoding plan carrying the supplied capacity bound and
48 /// action.
49 #[must_use]
50 #[inline(always)]
51 pub const fn new(max_output_units: usize, action: A) -> Self {
52 Self {
53 max_output_units,
54 action,
55 }
56 }
57}