qubit-codec 0.17.4

Core codec traits and buffer conversion primitives for Rust
Documentation
// =============================================================================
//    Copyright (c) 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Pending decoded value retained by buffered converters.

/// Decoded value retained after source input has been consumed.
///
/// # Type Parameters
///
/// - `Value`: Owned decoded value retained until downstream encoding succeeds.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub(in crate::transcode) struct PendingValue<Value> {
    /// Decoded logical value.
    value: Value,
    /// Source input index that produced this value.
    input_index: usize,
}

impl<Value> PendingValue<Value> {
    /// Creates a retained decoded value.
    ///
    /// # Parameters
    ///
    /// - `value`: Decoded logical value.
    /// - `input_index`: Source input index that produced the value.
    ///
    /// # Returns
    ///
    /// Returns pending-value state owned by the converter engine.
    #[inline]
    #[must_use]
    pub(in crate::transcode) const fn new(value: Value, input_index: usize) -> Self {
        Self { value, input_index }
    }

    /// Returns the source input index that produced this value.
    ///
    /// # Returns
    ///
    /// Returns the absolute source input index used for downstream encode
    /// errors.
    #[inline]
    #[must_use]
    pub(in crate::transcode) const fn input_index(&self) -> usize {
        self.input_index
    }

    /// Returns the decoded value.
    ///
    /// # Returns
    ///
    /// Returns the retained decoded value by shared reference.
    #[inline]
    #[must_use = "the decoded value must be inspected before encoding"]
    pub(in crate::transcode) const fn value(&self) -> &Value {
        &self.value
    }

    /// Consumes the pending state and returns the decoded value.
    ///
    /// # Returns
    ///
    /// Returns the owned decoded value.
    #[inline]
    #[must_use = "the decoded value must be retained for downstream encoding"]
    pub(in crate::transcode) fn into_value(self) -> Value {
        self.value
    }
}