qubit_argument/argument/constraint/length_metric.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//! Measurement units used by length validation.
9
10/// Identifies how an observed string or collection length was measured.
11///
12/// The metric is retained in structured errors so equal numeric lengths and
13/// constraints remain distinguishable across strings and collections.
14/// This enum is non-exhaustive; downstream matches must include a wildcard arm.
15///
16/// # Examples
17///
18/// ```
19/// use qubit_argument::LengthMetric;
20///
21/// let metric = LengthMetric::UnicodeScalars;
22/// assert!(matches!(metric, LengthMetric::UnicodeScalars));
23/// ```
24///
25/// ```compile_fail
26/// use qubit_argument::LengthMetric;
27///
28/// fn label(metric: LengthMetric) -> &'static str {
29/// match metric {
30/// LengthMetric::Bytes => "bytes",
31/// LengthMetric::UnicodeScalars => "Unicode scalars",
32/// LengthMetric::Elements => "elements",
33/// }
34/// }
35/// ```
36///
37/// ```compile_fail
38/// #![deny(unused_must_use)]
39/// use qubit_argument::LengthMetric;
40///
41/// LengthMetric::Bytes;
42/// ```
43#[non_exhaustive]
44#[must_use]
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum LengthMetric {
47 /// The number of bytes in a UTF-8 string.
48 Bytes,
49 /// The number of Unicode scalar values in a string.
50 UnicodeScalars,
51 /// The number of elements in a collection.
52 Elements,
53}