Skip to main content

qubit_argument/argument/constraint/
length_constraint.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//! Relationships used by string and collection length constraints.
9
10/// A numeric relationship required of a measured string or collection length.
11///
12/// [`LengthMetric`](super::LengthMetric) identifies the measurement unit in a
13/// structured validation error.
14///
15/// # Examples
16///
17/// ```
18/// use qubit_argument::LengthConstraint;
19///
20/// let constraint = LengthConstraint::InRange { min: 2, max: 5 };
21/// assert!(matches!(constraint, LengthConstraint::InRange { min: 2, max: 5 }));
22/// ```
23///
24/// ```compile_fail
25/// #![deny(unused_must_use)]
26/// use qubit_argument::LengthConstraint;
27///
28/// LengthConstraint::Exact(1);
29/// ```
30#[must_use]
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub enum LengthConstraint {
33    /// Requires exactly the specified length.
34    Exact(usize),
35    /// Requires at least the specified length.
36    AtLeast(usize),
37    /// Requires at most the specified length.
38    AtMost(usize),
39    /// Requires a length between `min` and `max`, inclusive.
40    InRange {
41        /// The inclusive minimum length.
42        min: usize,
43        /// The inclusive maximum length.
44        max: usize,
45    },
46}