Skip to main content

qubit_argument/argument/constraint/
range_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//! Numeric range constraints.
9
10use crate::argument::ArgumentBound;
11
12/// A numeric range with independently inclusive, exclusive, or absent bounds.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct RangeConstraint {
15    lower: ArgumentBound,
16    upper: ArgumentBound,
17}
18
19impl RangeConstraint {
20    /// Creates a range from its lower and upper bounds.
21    ///
22    /// The bounds are retained exactly as supplied and are not ordered or
23    /// otherwise validated.
24    #[inline]
25    pub fn new(lower: ArgumentBound, upper: ArgumentBound) -> Self {
26        Self { lower, upper }
27    }
28
29    /// Returns the lower bound of this range.
30    #[inline]
31    pub fn lower(&self) -> &ArgumentBound {
32        &self.lower
33    }
34
35    /// Returns the upper bound of this range.
36    #[inline]
37    pub fn upper(&self) -> &ArgumentBound {
38        &self.upper
39    }
40
41    /// Consumes this range and returns its lower and upper bounds.
42    ///
43    /// The first tuple element is the lower bound and the second is the upper
44    /// bound.
45    #[inline]
46    pub fn into_bounds(self) -> (ArgumentBound, ArgumentBound) {
47        let Self { lower, upper } = self;
48        (lower, upper)
49    }
50}