Skip to main content

qubit_budget/resource/quantity/
quantity_measurement.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Defines native measurements that cannot fit a resource quantity.
9
10use std::fmt;
11
12/// A native unsigned measurement whose value could not fit a resource quantity.
13///
14/// # Examples
15///
16/// ```
17/// use qubit_budget::QuantityMeasurement;
18///
19/// assert_eq!(QuantityMeasurement::U64(42).to_string(), "42");
20/// ```
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum QuantityMeasurement {
23    /// Measurement supplied by a Rust container or string length.
24    Usize(
25        /// Original machine-sized measurement.
26        usize,
27    ),
28    /// Measurement supplied by an API with a stable 64-bit quantity.
29    U64(
30        /// Original 64-bit measurement.
31        u64,
32    ),
33}
34
35impl fmt::Display for QuantityMeasurement {
36    /// Formats the native measurement without changing its numeric value.
37    ///
38    /// # Parameters
39    ///
40    /// * `formatter` - Formatter receiving the decimal measurement.
41    ///
42    /// # Returns
43    ///
44    /// Returns the result of writing the measurement.
45    ///
46    /// # Errors
47    ///
48    /// Returns [`std::fmt::Error`] when the formatter rejects the output.
49    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
50        match self {
51            Self::Usize(value) => value.fmt(formatter),
52            Self::U64(value) => value.fmt(formatter),
53        }
54    }
55}