Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 // SPDX-License-Identifier: MPL-2.0
2
3 //! This crate contains a performance-optimized type for generic version ranges and operations on
4 //! them.
5 //!
6 //! [`Ranges`] can represent version selectors such as `(>=1, <2) OR (==3) OR (>4)`. Internally,
7 //! it is an ordered list of contiguous intervals (segments) with inclusive, exclusive or open-ended
8 //! ends, similar to a `Vec<(Bound<T>, Bound<T>)>`.
9 //!
10 //! You can construct a basic range from one of the following build blocks. All other ranges are
11 //! concatenation, union, and complement of these basic ranges.
12 //! - [empty()](Ranges::empty): No version
13 //! - [full()](Ranges::full): All versions
14 //! - [singleton(v)](Ranges::singleton): Only the version v exactly
15 //! - [higher_than(v)](Ranges::higher_than): All versions `v <= versions`
16 //! - [strictly_higher_than(v)](Ranges::strictly_higher_than): All versions `v < versions`
17 //! - [lower_than(v)](Ranges::lower_than): All versions `versions <= v`
18 //! - [strictly_lower_than(v)](Ranges::strictly_lower_than): All versions `versions < v`
19 //! - [between(v1, v2)](Ranges::between): All versions `v1 <= versions < v2`
20 //!
21 //! [`Ranges`] is generic over any type that implements [`Ord`] + [`Clone`] and can represent all
22 //! kinds of slices with ordered coordinates, not just version ranges. While built as a
23 //! performance-critical piece of [pubgrub](https://github.com/pubgrub-rs/pubgrub), it can be
24 //! adopted for other domains, too.
25 //!
26 //! Note that there are limitations to the equality implementation: Given a `Ranges<u32>`,
27 //! the segments `(Unbounded, Included(42u32))` and `(Included(0), Included(42u32))` as well as
28 //! `(Included(1), Included(5))` and `(Included(1), Included(3)) + (Included(4), Included(5))`
29 //! are reported as unequal, even though the match the same versions: We can't tell that there isn't
30 //! a version between `0` and `-inf` or `3` and `4` respectively.
31 //!
32 //! ## Optional features
33 //!
34 //! * `serde`: serialization and deserialization for the version range, given that the version type
35 //! also supports it.
36 //! * `proptest`: Exports are proptest strategy for [`Ranges<u32>`].
37
38 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#;
39 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
40 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
41 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#};
42 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeBoundsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#;
43
44 #[cfg(any(feature = "proptest", test))]
45 use proptestrust-analyzer cargo proptest 1.8.0 crate/::preluderust-analyzer cargo proptest 1.8.0 prelude/::*;
46 use smallvecrust-analyzer cargo smallvec 1.15.1 crate/::{smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!, SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#};
47
48 /// Ranges represents multiple intervals of a continuous range of monotone increasing values.
49 ///
50 /// Internally, [`Ranges`] are an ordered list of segments, where segment is a bounds pair.
51 ///
52 /// Invariants:
53 /// 1. The segments are sorted, from lowest to highest (through `Ord`).
54 /// 2. Each segment contains at least one version (start < end).
55 /// 3. There is at least one version between two segments.
56 ///
57 /// These ensure that equivalent instances have an identical representation, which is important
58 /// for `Eq` and `Hash`. Note that this representation cannot strictly guaranty equality of
59 /// [`Ranges`] with equality of its representation without also knowing the nature of the underlying
60 /// versions. In particular, if the version space is discrete, different representations, using
61 /// different types of bounds (exclusive/inclusive) may correspond to the same set of existing
62 /// versions. It is a tradeoff we acknowledge, but which makes representations of continuous version
63 /// sets more accessible, to better handle features like pre-releases and other types of version
64 /// modifiers. For example, `[(Included(3u32), Excluded(7u32))]` and
65 /// `[(Included(3u32), Included(6u32))]` refer to the same version set, since there is no version
66 /// between 6 and 7, which this crate doesn't know about.
67
68 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
69 #[cfg_attr(feature = "serde", derive(serderust-analyzer cargo serde 1.0.219 crate/::Serializerust-analyzer cargo serde_derive 1.0.219 Serialize:))]
70 #[cfg_attr(feature = "serde", serde(transparent))]
71 pub struct Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
72 /// Profiling in <https://github.com/pubgrub-rs/pubgrub/pull/262#discussion_r1804276278> showed
73 /// that a single stack entry is the most efficient. This is most likely due to `Interval<V>`
74 /// being large.
75 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>; 1]>,
76 }
77
78 // TODO: Replace the tuple type with a custom enum inlining the bounds to reduce the type's size.
79 type Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V> = (Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>);
80
81 impl<V> Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
82 /// Empty set of versions.
83 pub fn emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().() -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
84 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
85 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().(),
86 }
87 }
88
89 /// Set of all possible versions
90 pub fn fullrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]full().() -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
91 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
92 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)],
93 }
94 }
95
96 /// Set of all versions higher or equal to some version
97 pub fn higher_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]higher_than().(v: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
98 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
99 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)],
100 }
101 }
102
103 /// Set of all versions higher to some version
104 pub fn strictly_higher_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]strictly_higher_than().(v: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
105 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
106 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)],
107 }
108 }
109
110 /// Set of all versions lower to some version
111 pub fn strictly_lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]strictly_lower_than().(v: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
112 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
113 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()))],
114 }
115 }
116
117 /// Set of all versions lower or equal to some version
118 pub fn lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]lower_than().(v: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
119 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
120 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()))],
121 }
122 }
123
124 /// Set of versions greater or equal to `v1` but less than `v2`.
125 pub fn betweenrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]between().(v1: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>, v2: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
126 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
127 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v1.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v2.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()))],
128 }
129 }
130
131 /// Whether the set is empty, i.e. it has not ranges
132 pub fn is_emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]is_empty().(&self) -> bool {
133 self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..is_emptyrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]is_empty().()
134 }
135 }
136
137 impl<V: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
138 /// Set containing exactly one version
139 pub fn singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(v: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
140 let v = v.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
141 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
142 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v))],
143 }
144 }
145
146 /// Returns the complement, which contains everything not included in `self`.
147 pub fn complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().(&self) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
148 match self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() {
149 // Complement of ∅ is ∞
150 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::fullrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]full().(),
151
152 // Complement of ∞ is ∅
153 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)) => Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().(),
154
155 // First high bound is +∞
156 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)) => Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::strictly_lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]strictly_lower_than().(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
157 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)) => Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]lower_than().(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
158
159 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v))) => {
160 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::negate_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]negate_segments().(Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()), &self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().)
161 }
162 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v))) => {
163 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::negate_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]negate_segments().(Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()), &self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().)
164 }
165 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_)))
166 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_)))
167 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_)))
168 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_))) => Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::negate_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]negate_segments().(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, &self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.),
169 }
170 }
171
172 /// Helper function performing the negation of intervals in segments.
173 fn negate_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]negate_segments().(start: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, segments: &[Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>]) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
174 let mut complement_segments = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
175 let mut start = start;
176 for (v1, v2) in segments {
177 complement_segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((
178 start,
179 match v1 {
180 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v) => Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
181 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v) => Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
182 Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
183 },
184 ));
185 start = match v2 {
186 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v) => Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
187 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v) => Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()),
188 Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#,
189 }
190 }
191 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(start, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) {
192 complement_segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((start, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#));
193 }
194
195 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
196 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: complement_segments,
197 }
198 }
199 }
200
201 impl<V: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#> Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
202 /// If self contains exactly a single version, return it, otherwise, return [None].
203 pub fn as_singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]as_singleton().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&V> {
204 match self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..as_slicerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]as_slice().() {
205 [(Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v1), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v2))] => {
206 if v1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().v2 {
207 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v1)
208 } else {
209 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
210 }
211 }
212 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
213 }
214 }
215
216 /// Convert to something that can be used with
217 /// [BTreeMap::range](std::collections::BTreeMap::range).
218 /// All versions contained in self, will be in the output,
219 /// but there may be versions in the output that are not contained in self.
220 /// Returns None if the range is empty.
221 pub fn bounding_rangerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]bounding_range().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>)> {
222 self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(start, _)| {
223 let end = self
224 .segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.
225 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().()
226 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("if there is a first element, there must be a last element");
227 (start.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().(), end.1.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().())
228 })
229 }
230
231 /// Returns true if self contains the specified value.
232 pub fn containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().<Q>(&self, version: &Q) -> bool
233 where
234 V: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
235 Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#,
236 {
237 self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.
238 .binary_search_byrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search_by().(|segment| {
239 // We have to reverse because we need the segment wrt to the version, while
240 // within bounds tells us the version wrt to the segment.
241 within_boundsrust-analyzer cargo astral-version-ranges 0.1.4 within_bounds().(version, segment).reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]reverse().()
242 })
243 // An equal interval is one that contains the version
244 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()
245 }
246
247 /// Returns true if self contains the specified values.
248 ///
249 /// The `versions` iterator must be sorted.
250 /// Functionally equivalent to `versions.map(|v| self.contains(v))`.
251 /// Except it runs in `O(size_of_range + len_of_versions)` not `O(size_of_range * len_of_versions)`
252 pub fn contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().<'s, I, BV>(&'s self, versions: I) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = bool> + 's
253 where
254 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = BV> + 's,
255 BV: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<V> + 's,
256 {
257 #[cfg(debug_assertions)]
258 let mut last: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BV> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
259 versions.scanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#scan().(0, move |i, v| {
260 #[cfg(debug_assertions)]
261 {
262 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(l) = last.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
263 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
264 l.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().() <= v.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
265 "`contains_many` `versions` argument incorrectly sorted"
266 );
267 }
268 }
269 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(segment) = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().i) {
270 match within_boundsrust-analyzer cargo astral-version-ranges 0.1.4 within_bounds().(v.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(), segment) {
271 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false),
272 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
273 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1,
274 }
275 }
276 #[cfg(debug_assertions)]
277 {
278 last = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v);
279 }
280 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false)
281 })
282 }
283
284 /// Construct a simple range from anything that impls [RangeBounds] like `v1..v2`.
285 pub fn from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]from_range_bounds().<R, IV>(bounds: R) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]
286 where
287 R: RangeBoundsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#<IV>,
288 IV: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<V>,
289 {
290 let start = match bounds.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#start_bound().() {
291 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v) => Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
292 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v) => Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
293 Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#,
294 };
295 let end = match bounds.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#end_bound().() {
296 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v) => Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
297 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v) => Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()),
298 Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#,
299 };
300 if valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(&start, &end) {
301 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
302 segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: smallvecrust-analyzer cargo smallvec 1.15.1 smallvec!![(start, end)],
303 }
304 } else {
305 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().()
306 }
307 }
308
309 /// See [`Ranges`] for the invariants checked.
310 fn check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().(self) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
311 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(debug_assertions) {
312 for p in self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..as_slicerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]as_slice().().windowsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]windows().(2) {
313 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(&p[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1, &p[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..0));
314 }
315 for (s, e) in self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
316 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(s, e));
317 }
318 }
319 self
320 }
321 }
322
323 /// Implementing `PartialOrd` for start `Bound` of an interval.
324 ///
325 /// Legend: `∞` is unbounded, `[1,2]` is `>=1,<=2`, `]1,2[` is `>1,<2`.
326 ///
327 /// ```text
328 /// left: ∞-------]
329 /// right: [-----]
330 /// left is smaller, since it starts earlier.
331 ///
332 /// left: [-----]
333 /// right: ]-----]
334 /// left is smaller, since it starts earlier.
335 /// ```
336 fn cmp_bounds_startrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_start().<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(left: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>, right: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
337 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(match (left, right) {
338 // left: ∞-----
339 // right: ∞-----
340 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#,
341 // left: [---
342 // right: ∞-----
343 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_left), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
344 // left: ]---
345 // right: ∞-----
346 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_left), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
347 // left: ∞-----
348 // right: [---
349 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_right)) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
350 // left: [----- OR [----- OR [-----
351 // right: [--- OR [----- OR [---
352 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
353 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => match left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). {
354 // left: ]-----
355 // right: [---
356 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
357 // left: ]-----
358 // right: [---
359 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
360 // left: ]---
361 // right: [-----
362 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
363 },
364 // left: ∞-----
365 // right: ]---
366 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_right)) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
367 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => match left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). {
368 // left: [-----
369 // right: ]---
370 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
371 // left: [-----
372 // right: ]---
373 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
374 // left: [---
375 // right: ]-----
376 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
377 },
378 // left: ]----- OR ]----- OR ]---
379 // right: ]--- OR ]----- OR ]-----
380 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
381 })
382 }
383
384 /// Implementing `PartialOrd` for end `Bound` of an interval.
385 ///
386 /// We flip the unbounded ranges from `-∞` to `∞`, while `V`-valued bounds checks remain the same.
387 ///
388 /// Legend: `∞` is unbounded, `[1,2]` is `>=1,<=2`, `]1,2[` is `>1,<2`.
389 ///
390 /// ```text
391 /// left: [--------∞
392 /// right: [-----]
393 /// left is greater, since it starts earlier.
394 ///
395 /// left: [-----[
396 /// right: [-----]
397 /// left is smaller, since it ends earlier.
398 /// ```
399 fn cmp_bounds_endrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_end().<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(left: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>, right: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<&V>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
400 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(match (left, right) {
401 // left: -----∞
402 // right: -----∞
403 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#,
404 // left: ---]
405 // right: -----∞
406 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_left), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
407 // left: ---[
408 // right: -----∞
409 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_left), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
410 // left: -----∞
411 // right: ---]
412 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_right)) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
413 // left: -----] OR -----] OR ---]
414 // right: ---] OR -----] OR -----]
415 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
416 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => match left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). {
417 // left: ---[
418 // right: -----]
419 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
420 // left: -----[
421 // right: -----]
422 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
423 // left: -----[
424 // right: ---]
425 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
426 },
427 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(_right)) => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
428 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => match left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). {
429 // left: ---]
430 // right: -----[
431 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
432 // left: -----]
433 // right: -----[
434 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
435 // left: -----]
436 // right: ---[
437 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
438 },
439 // left: -----[ OR -----[ OR ---[
440 // right: ---[ OR -----[ OR -----[
441 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => left.partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#partial_cmp().(right)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
442 })
443 }
444
445 impl<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#> PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
446 /// A simple ordering scheme where we zip the segments and compare all bounds in order. If all
447 /// bounds are equal, the longer range is considered greater. (And if all zipped bounds are
448 /// equal and we have the same number of segments, the ranges are equal).
449 fn partial_cmprust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
450 for (left, right) in self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) {
451 let start_cmp = cmp_bounds_startrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_start().(left.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), right.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
452 if start_cmp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# {
453 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start_cmp);
454 }
455 let end_cmp = cmp_bounds_endrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_end().(left.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(), right.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
456 if end_cmp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# {
457 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end_cmp);
458 }
459 }
460 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][Ord]cmp().(&other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().()))
461 }
462 }
463
464 impl<V: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#> Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
465 fn cmprust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
466 self.partial_cmprust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`PartialOrd<Self>`]partial_cmp().(other)
467 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("PartialOrd must be `Some(Ordering)` for types that implement `Ord`")
468 }
469 }
470
471 /// The ordering of the version wrt to the interval.
472 /// ```text
473 /// |-------|
474 /// ^ ^ ^
475 /// less equal greater
476 /// ```
477 fn within_boundsrust-analyzer cargo astral-version-ranges 0.1.4 within_bounds().<Q, V>(version: &Q, segment: &Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#
478 where
479 V: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
480 Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#,
481 {
482 let below_lower_bound = match segment {
483 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(start), _) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().start.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
484 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(start), _) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().start.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
485 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) => false,
486 };
487 if below_lower_bound {
488 return Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#;
489 }
490 let below_upper_bound = match segment {
491 (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => true,
492 (_, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(end)) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().end.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
493 (_, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(end)) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().end.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
494 };
495 if below_upper_bound {
496 return Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#;
497 }
498 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#
499 }
500
501 /// A valid segment is one where at least one version fits between start and end
502 fn valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().<T: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(start: &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<T>, end: &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<T>) -> bool {
503 match (start, end) {
504 // Singleton interval are allowed
505 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(s), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(e)) => s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().e,
506 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(s), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(e)) => s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().e,
507 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(s), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(e)) => s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().e,
508 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(s), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(e)) => s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().e,
509 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) | (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => true,
510 }
511 }
512
513 /// The end of one interval is before the start of the next one, so they can't be concatenated
514 /// into a single interval. The `union` method calling with both intervals and then the intervals
515 /// switched. If either is true, the intervals are separate in the union and if both are false, they
516 /// are merged.
517 /// ```text
518 /// True for these two:
519 /// |----|
520 /// |-----|
521 /// ^ end ^ start
522 /// False for these two:
523 /// |----|
524 /// |-----|
525 /// Here it depends: If they both exclude the position they share, there is a version in between
526 /// them that blocks concatenation
527 /// |----|
528 /// |-----|
529 /// ```
530 fn end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(end: &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, start: &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>) -> bool {
531 match (end, start) {
532 (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => false,
533 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) => false,
534 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().right,
535 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().right,
536 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().right,
537 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(left), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().right,
538 }
539 }
540
541 fn left_start_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_start_is_smaller().<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(left: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, right: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>) -> bool {
542 match (left, right) {
543 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) => true,
544 (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => false,
545 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
546 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
547 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
548 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().r,
549 }
550 }
551
552 fn left_end_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_end_is_smaller().<V: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(left: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, right: Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>) -> bool {
553 match (left, right) {
554 (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => true,
555 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) => false,
556 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
557 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
558 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().r,
559 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().r,
560 }
561 }
562
563 /// Group adjacent versions locations.
564 ///
565 /// ```text
566 /// [None, 3, 6, 7, None] -> [(3, 7)]
567 /// [3, 6, 7, None] -> [(None, 7)]
568 /// [3, 6, 7] -> [(None, None)]
569 /// [None, 1, 4, 7, None, None, None, 8, None, 9] -> [(1, 7), (8, 8), (9, None)]
570 /// ```
571 fn group_adjacent_locationsrust-analyzer cargo astral-version-ranges 0.1.4 group_adjacent_locations().(
572 mut locations: impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>>,
573 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>)> {
574 // If the first version matched, then the lower bound of that segment is not needed
575 let mut seg = locations.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Option<T>>`]flatten().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|ver| (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ver)));
576 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || {
577 for ver in locations.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().() {
578 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ver) = ver {
579 // As long as were still matching versions, we keep merging into the currently matching segment
580 seg = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((seg.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ver), |(s, _)| s), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ver)));
581 } else {
582 // If we have found a version that doesn't match, then right the merge segment and prepare for a new one.
583 if seg.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
584 return seg.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().();
585 }
586 }
587 }
588 // If the last version matched, then write out the merged segment but the upper bound is not needed.
589 seg.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(s, _)| (s, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#))
590 })
591 }
592
593 impl<V: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
594 /// Computes the union of this `Ranges` and another.
595 pub fn unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
596 let mut output = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
597 let mut accumulator: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<_>, &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<_>)> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
598 let mut left_iter = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
599 let mut right_iter = other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
600 loop {
601 let smaller_interval = match (left_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().(), right_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().()) {
602 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((left_start, left_end)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((right_start, right_end))) => {
603 if left_start_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_start_is_smaller().(left_start.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().(), right_start.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().()) {
604 left_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
605 (left_start, left_end)
606 } else {
607 right_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
608 (right_start, right_end)
609 }
610 }
611 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((left_start, left_end)), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
612 left_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
613 (left_start, left_end)
614 }
615 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((right_start, right_end))) => {
616 right_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
617 (right_start, right_end)
618 }
619 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => break,
620 };
621
622 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(accumulator_) = accumulator {
623 if end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(accumulator_.1, smaller_interval.0) {
624 output.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((accumulator_.0.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().(), accumulator_.1.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().()));
625 accumulator = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(smaller_interval);
626 } else {
627 let accumulator_end = match (accumulator_.1, smaller_interval.1) {
628 (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) | (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) => &Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#,
629 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r) | Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) if l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().r => accumulator_.1,
630 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l) | Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r) | Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => {
631 if l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().r {
632 accumulator_.1
633 } else {
634 smaller_interval.1
635 }
636 }
637 };
638 accumulator = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((accumulator_.0, accumulator_end));
639 }
640 } else {
641 accumulator = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(smaller_interval)
642 }
643 }
644
645 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(accumulator) = accumulator {
646 output.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((accumulator.0.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().(), accumulator.1.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().()));
647 }
648
649 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: output }.check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().()
650 }
651
652 /// Computes the intersection of two sets of versions.
653 pub fn intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] {
654 let mut output = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
655 let mut left_iter = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
656 let mut right_iter = other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
657 // By the definition of intersection any point that is matched by the output
658 // must have a segment in each of the inputs that it matches.
659 // Therefore, every segment in the output must be the intersection of a segment from each of the inputs.
660 // It would be correct to do the "O(n^2)" thing, by computing the intersection of every segment from one input
661 // with every segment of the other input, and sorting the result.
662 // We can avoid the sorting by generating our candidate segments with an increasing `end` value.
663 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(((left_start, left_end), (right_start, right_end))) =
664 left_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]zip().(right_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().())
665 {
666 // The next smallest `end` value is going to come from one of the inputs.
667 let left_end_is_smaller = left_end_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_end_is_smaller().(left_end.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().(), right_end.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().());
668 // Now that we are processing `end` we will never have to process any segment smaller than that.
669 // We can ensure that the input that `end` came from is larger than `end` by advancing it one step.
670 // `end` is the smaller available input, so we know the other input is already larger than `end`.
671 // Note: We can call `other_iter.next_if( == end)`, but the ends lining up is rare enough that
672 // it does not end up being faster in practice.
673 let (other_start, end) = if left_end_is_smaller {
674 left_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
675 (right_start, left_end)
676 } else {
677 right_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
678 (left_start, right_end)
679 };
680 // `start` will either come from the input `end` came from or the other input, whichever one is larger.
681 // The intersection is invalid if `start` > `end`.
682 // But, we already know that the segments in our input are valid.
683 // So we do not need to check if the `start` from the input `end` came from is smaller than `end`.
684 // If the `other_start` is larger than end, then the intersection will be invalid.
685 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(other_start, end) {
686 // Note: We can call `this_iter.next_if(!valid_segment(other_start, this_end))` in a loop.
687 // But the checks make it slower for the benchmarked inputs.
688 continue;
689 }
690 let start = match (left_start, right_start) {
691 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(r)) => Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(l, r)),
692 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r)) => Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(l, r)),
693
694 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(i), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(e)) | (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(e), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(i)) => {
695 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().e {
696 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(e)
697 } else {
698 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(i)
699 }
700 }
701 (s, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) | (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, s) => s.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`]as_ref().(),
702 };
703 // Now we clone and push a new segment.
704 // By dealing with references until now we ensure that NO cloning happens when we reject the segment.
705 output.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((start.clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<&T>`]cloned().(), end.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().()))
706 }
707
708 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.: output }.check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().()
709 }
710
711 /// Return true if there can be no `V` so that `V` is contained in both `self` and `other`.
712 ///
713 /// Note that we don't know that set of all existing `V`s here, so we only check if the segments
714 /// are disjoint, not if no version is contained in both.
715 pub fn is_disjointrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]is_disjoint().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]) -> bool {
716 // The operation is symmetric
717 let mut left_iter = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
718 let mut right_iter = other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
719
720 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((left, right)) = left_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]zip().(right_iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().()) {
721 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(&right.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), &left.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().()) {
722 left_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
723 } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(&left.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), &right.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().()) {
724 right_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
725 } else {
726 return false;
727 }
728 }
729
730 // The remaining element(s) can't intersect anymore
731 true
732 }
733
734 /// Return true if any `V` that is contained in `self` is also contained in `other`.
735 ///
736 /// Note that we don't know that set of all existing `V`s here, so we only check if all
737 /// segments `self` are contained in a segment of `other`.
738 pub fn subset_ofrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]subset_of().(&self, other: &Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]) -> bool {
739 let mut containing_iter = other.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
740 let mut subset_iter = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
741 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut containing_elem) = containing_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().() else {
742 // As long as we have subset elements, we need containing elements
743 return subset_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().();
744 };
745
746 for subset_elem in subset_iter {
747 // Check if the current containing element ends before the subset element.
748 // There needs to be another containing element for our subset element in this case.
749 while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(&subset_elem.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), &containing_elem.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().()) {
750 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(containing_elem_) = containing_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().() {
751 containing_elem = containing_elem_;
752 } else {
753 return false;
754 };
755 }
756
757 let start_contained =
758 left_start_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_start_is_smaller().(containing_elem.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), subset_elem.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().());
759
760 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().start_contained {
761 // The start element is not contained
762 return false;
763 }
764
765 let end_contained =
766 left_end_is_smallerrust-analyzer cargo astral-version-ranges 0.1.4 left_end_is_smaller().(subset_elem.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(), containing_elem.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().());
767
768 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().end_contained {
769 // The end element is not contained
770 return false;
771 }
772 }
773
774 true
775 }
776
777 /// Returns a simpler representation that contains the same versions.
778 ///
779 /// For every one of the Versions provided in versions the existing range and the simplified range will agree on whether it is contained.
780 /// The simplified version may include or exclude versions that are not in versions as the implementation wishes.
781 ///
782 /// If none of the versions are contained in the original than the range will be returned unmodified.
783 /// If the range includes a single version, it will be returned unmodified.
784 /// If all the versions are contained in the original than the range will be simplified to `full`.
785 ///
786 /// If the given versions are not sorted the correctness of this function is not guaranteed.
787 pub fn simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().<'s, I, BV>(&self, versions: I) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]
788 where
789 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = BV> + 's,
790 BV: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<V> + 's,
791 {
792 // Do not simplify singletons
793 if self.as_singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]as_singleton().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
794 return self.clonerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][Clone]clone().();
795 }
796
797 #[cfg(debug_assertions)]
798 let mut last: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BV> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
799 // Return the segment index in the range for each version in the range, None otherwise
800 let version_locations = versions.scanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#scan().(0, move |i, v| {
801 #[cfg(debug_assertions)]
802 {
803 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(l) = last.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
804 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
805 l.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().() <= v.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(),
806 "`simplify` `versions` argument incorrectly sorted"
807 );
808 }
809 }
810 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(segment) = self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().i) {
811 match within_boundsrust-analyzer cargo astral-version-ranges 0.1.4 within_bounds().(v.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(), segment) {
812 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
813 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().i)),
814 Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1,
815 }
816 }
817 #[cfg(debug_assertions)]
818 {
819 last = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v);
820 }
821 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
822 });
823 let mut kept_segments = group_adjacent_locationsrust-analyzer cargo astral-version-ranges 0.1.4 group_adjacent_locations().(version_locations).peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
824
825 // Do not return null sets
826 if kept_segments.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
827 return self.clonerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][Clone]clone().();
828 }
829
830 self.keep_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]keep_segments().(kept_segments)
831 }
832
833 /// Create a new range with a subset of segments at given location bounds.
834 ///
835 /// Each new segment is constructed from a pair of segments, taking the
836 /// start of the first and the end of the second.
837 fn keep_segmentsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]keep_segments().(
838 &self,
839 kept_segments: impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>)>,
840 ) -> Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
841 let mut segments = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
842 for (s, e) in kept_segments {
843 segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((
844 s.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, |s| self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().s]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..0.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().()),
845 e.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, |e| self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments.[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().e]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..1.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Bound<T>`][Clone]clone().()),
846 ));
847 }
848 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`] { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments. }.check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().()
849 }
850
851 /// Iterate over the parts of the range.
852 pub fn iterrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]iter().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, &Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>)> {
853 self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(start, end)| (start, end))
854 }
855 }
856
857 // Newtype to avoid leaking our internal representation.
858 pub struct RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#<V>(smallvecrust-analyzer cargo smallvec 1.15.1 crate/::IntoIterrust-analyzer cargo smallvec 1.15.1 IntoIter#<[Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>; 1]>);
859
860 impl<V> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#<V> {
861 type Itemrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][Iterator]Item# = Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>;
862
863 fn nextrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
864 self.0rust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#0..nextrust-analyzer cargo smallvec 1.15.1 impl#[`IntoIter<A>`][Iterator]next().()
865 }
866
867 fn size_hintrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
868 (self.0rust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.0rust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#0..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().()))
869 }
870 }
871
872 impl<V> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#<V> {}
873
874 impl<V> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#<V> {
875 fn next_backrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`RangesIter<V>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
876 self.0rust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#0..next_backrust-analyzer cargo smallvec 1.15.1 impl#[`IntoIter<A>`][DoubleEndedIterator]next_back().()
877 }
878 }
879
880 impl<V> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
881 type Itemrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][IntoIterator]Item# = (Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>);
882 // Newtype to avoid leaking our internal representation.
883 type IntoIterrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][IntoIterator]IntoIter# = RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#<V>;
884
885 fn into_iterrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# {
886 RangesIterrust-analyzer cargo astral-version-ranges 0.1.4 RangesIter#(self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..into_iterrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][IntoIterator]into_iter().())
887 }
888 }
889
890 impl<V: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#> FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>)> for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
891 /// Constructor from arbitrary, unsorted and potentially overlapping ranges.
892 ///
893 /// This is equivalent, but faster, to computing the [`Ranges::union`] of the
894 /// [`Ranges::from_range_bounds`] of each segment.
895 fn from_iterrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`FromIterator<(Bound<V>, Bound<V>)>`]from_iter().<T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>)>>(iter: T) -> Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`FromIterator<(Bound<V>, Bound<V>)>`] {
896 // We have three constraints we need to fulfil:
897 // 1. The segments are sorted, from lowest to highest (through `Ord`): By sorting.
898 // 2. Each segment contains at least one version (start < end): By skipping invalid
899 // segments.
900 // 3. There is at least one version between two segments: By merging overlapping elements.
901 //
902 // Technically, the implementation has a O(n²) worst case complexity since we're inserting
903 // and removing. This has two motivations: One is that we don't have any performance
904 // critical usages of this method as of this writing, so we have no real world benchmark.
905 // The other is that we get the elements from an iterator, so to avoid moving elements
906 // around we would first need to build a different, sorted collection with extra
907 // allocation(s), before we could build our real segments. --Konsti
908
909 // For this implementation, we choose to only build a single smallvec and insert or remove
910 // in it, instead of e.g. collecting the segments into a sorted datastructure first and then
911 // construction the second smallvec without shifting.
912 let mut segments: SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>; 1]> = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
913
914 for segment in iter {
915 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().valid_segmentrust-analyzer cargo astral-version-ranges 0.1.4 valid_segment().(&segment.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), &segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().()) {
916 continue;
917 }
918 // Find where to insert the new segment
919 let insertion_point = segments.partition_pointrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]partition_point().(|elem: &Intervalrust-analyzer cargo astral-version-ranges 0.1.4 Interval#<V>| {
920 cmp_bounds_startrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_start().(elem.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(), segment.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().())
921 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
922 .is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().()
923 });
924 // Is it overlapping with the previous segment?
925 let previous_overlapping = insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0
926 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(
927 &segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
928 &segment.start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(),
929 );
930
931 // Is it overlapping with the following segment? We'll check if there's more than one
932 // overlap later.
933 let next_overlapping = insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().segments.lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().()
934 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(
935 &segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
936 &segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(),
937 );
938
939 match (previous_overlapping, next_overlapping) {
940 (true, true) => {
941 // previous: |------|
942 // segment: |------|
943 // following: |------|
944 // final: |---------------|
945 //
946 // OR
947 //
948 // previous: |------|
949 // segment: |-----------|
950 // following: |----|
951 // final: |---------------|
952 //
953 // OR
954 //
955 // previous: |------|
956 // segment: |----------------|
957 // following: |----| |------|
958 // final: |------------------------|
959 // We merge all three segments into one, which is effectively removing one of
960 // two previously inserted and changing the bounds on the other.
961
962 // Remove all elements covered by the final element
963 let mut following = segments.removerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]remove().(insertion_point);
964 while insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().segments.lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().()
965 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(
966 &segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
967 &segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(),
968 )
969 {
970 following = segments.removerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]remove().(insertion_point);
971 }
972
973 // Set end to max(segment.end, <last overlapping segment>.end)
974 if cmp_bounds_endrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_end().(segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(), following.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().())
975 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
976 .is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().()
977 {
978 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut()..1 = following.1;
979 } else {
980 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut()..1 = segment.1;
981 }
982 }
983 (true, false) => {
984 // previous: |------|
985 // segment: |------|
986 // following: |------|
987 //
988 // OR
989 //
990 // previous: |----------|
991 // segment: |---|
992 // following: |------|
993 //
994 // final: |----------| |------|
995 // We can reuse the existing element by extending it.
996
997 // Set end to max(segment.end, <previous>.end)
998 if cmp_bounds_endrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_end().(
999 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
1000 segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
1001 )
1002 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
1003 .is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().()
1004 {
1005 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut()..1 = segment.1;
1006 }
1007 }
1008 (false, true) => {
1009 // previous: |------|
1010 // segment: |------|
1011 // following: |------|
1012 // final: |------| |----------|
1013 //
1014 // OR
1015 //
1016 // previous: |------|
1017 // segment: |----------|
1018 // following: |---|
1019 // final: |------| |----------|
1020 //
1021 // OR
1022 //
1023 // previous: |------|
1024 // segment: |------------|
1025 // following: |---| |------|
1026 //
1027 // final: |------| |-----------------|
1028 // We can reuse the existing element by extending it.
1029
1030 // Remove all fully covered segments so the next element is the last one that
1031 // overlaps.
1032 while insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().segments.lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().()
1033 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().end_before_start_with_gaprust-analyzer cargo astral-version-ranges 0.1.4 end_before_start_with_gap().(
1034 &segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(),
1035 &segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..start_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]start_bound().(),
1036 )
1037 {
1038 // We know that the one after also overlaps, so we can drop the current
1039 // following.
1040 segments.removerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]remove().(insertion_point);
1041 }
1042
1043 // Set end to max(segment.end, <last overlapping segment>.end)
1044 if cmp_bounds_endrust-analyzer cargo astral-version-ranges 0.1.4 cmp_bounds_end().(segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index().insertion_point]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Index<I>`]index()..end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().(), segment.end_boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]end_bound().())
1045 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
1046 .is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().()
1047 {
1048 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut().insertion_point]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut()..1 = segment.1;
1049 }
1050 segments[rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut().insertion_point]rust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`IndexMut<I>`]index_mut()..0 = segment.0;
1051 }
1052 (false, false) => {
1053 // previous: |------|
1054 // segment: |------|
1055 // following: |------|
1056 //
1057 // final: |------| |------| |------|
1058
1059 // This line is O(n), which makes the algorithm O(n²), but it should be good
1060 // enough for now.
1061 segments.insertrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]insert().(insertion_point, segment);
1062 }
1063 }
1064 }
1065
1066 Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`FromIterator<(Bound<V>, Bound<V>)>`] { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments. }.check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().()
1067 }
1068 }
1069
1070 // REPORT ######################################################################
1071
1072 impl<V: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
1073 fn fmtrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1074 if self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..is_emptyrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]is_empty().() {
1075 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "∅")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1076 } else {
1077 for (idx, segment) in self.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1078 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
1079 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, " | ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1080 }
1081 match segment {
1082 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "*")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1083 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v)) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "<={v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1084 (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v)) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "<{v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1085 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">={v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1086 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(b)) => {
1087 if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().b {
1088 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "=={v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
1089 } else {
1090 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">={v}, <={b}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
1091 }
1092 }
1093 (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(v), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(b)) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">={v}, <{b}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1094 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">{v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1095 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(b)) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">{v}, <={b}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1096 (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(v), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(b)) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ">{v}, <{b}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1097 };
1098 }
1099 }
1100 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1101 }
1102 }
1103
1104 // SERIALIZATION ###############################################################
1105
1106 #[cfg(feature = "serde")]
1107 impl<'de, V: serderust-analyzer cargo serde 1.0.219 crate/::Deserializerust-analyzer cargo serde 1.0.219 de/Deserialize#<'de>> serderust-analyzer cargo serde 1.0.219 crate/::Deserializerust-analyzer cargo serde 1.0.219 de/Deserialize#<'de> for Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<V> {
1108 fn deserializerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`Deserialize<'de>`]deserialize().<D: serderust-analyzer cargo serde 1.0.219 crate/::Deserializerrust-analyzer cargo serde 1.0.219 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde 1.0.219 de/Deserializer#Error#> {
1109 // This enables conversion from the "old" discrete implementation of `Ranges` to the new
1110 // bounded one.
1111 //
1112 // Serialization is always performed in the new format.
1113 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(serderust-analyzer cargo serde 1.0.219 crate/::Deserializerust-analyzer cargo serde_derive 1.0.219 Deserialize:)]
1114 #[serde(untagged)]
1115 enum EitherIntervalrust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#<V> {
1116 Brust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#B#(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<V>),
1117 Drust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#D#(V, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<V>),
1118 }
1119
1120 let bounds: SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#<[EitherIntervalrust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#<V>; 2]> =
1121 serderust-analyzer cargo serde 1.0.219 crate/::Deserializerust-analyzer cargo serde 1.0.219 de/Deserialize#::deserializerust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`][`Deserialize<'de>`]deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1122
1123 let mut segments = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
1124 for i in bounds {
1125 match i {
1126 EitherIntervalrust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#::Brust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#B#(l, r) => segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((l, r)),
1127 EitherIntervalrust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#::Drust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#D#(l, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r)) => segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(r))),
1128 EitherIntervalrust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#::Drust-analyzer cargo astral-version-ranges 0.1.4 EitherInterval#D#(l, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(l), Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)),
1129 }
1130 }
1131
1132 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges# { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments. })
1133 }
1134 }
1135
1136 /// Generate version sets from a random vector of deltas between randomly inclusive or exclusive
1137 /// bounds.
1138 #[cfg(any(feature = "proptest", test))]
1139 pub fn proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().() -> impl Strategyrust-analyzer cargo proptest 1.8.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.8.0 strategy/traits/Strategy#Value# = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u32>> {
1140 (
1141 anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<bool>(),
1142 proprust-analyzer cargo proptest 1.8.0 prelude/prop/::collectionrust-analyzer cargo proptest 1.8.0 collection/::vecrust-analyzer cargo proptest 1.8.0 collection/vec().(anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<(u32, bool)>(), 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#10),
1143 )
1144 .prop_maprust-analyzer cargo proptest 1.8.0 strategy/traits/Strategy#prop_map().(|(start_unbounded, deltas)| {
1145 let mut start = if start_unbounded {
1146 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#)
1147 } else {
1148 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1149 };
1150 let mut largest: u32 = 0;
1151 let mut last_bound_was_inclusive = false;
1152 let mut segments = SmallVecrust-analyzer cargo smallvec 1.15.1 SmallVec#::newrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]new().();
1153 for (delta, inclusive) in deltas {
1154 // Add the offset to the current bound
1155 largest = match largest.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]checked_add().(delta) {
1156 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) => s,
1157 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
1158 // Skip this offset, if it would result in a too large bound.
1159 continue;
1160 }
1161 };
1162
1163 let current_bound = if inclusive {
1164 Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(largest)
1165 } else {
1166 Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(largest)
1167 };
1168
1169 // If we already have a start bound, the next offset defines the complete range.
1170 // If we don't have a start bound, we have to generate one.
1171 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start_bound) = start.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
1172 // If the delta from the start bound is 0, the only authorized configuration is
1173 // Included(x), Included(x)
1174 if delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(start_bound, Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(_)) && inclusive) {
1175 start = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start_bound);
1176 continue;
1177 }
1178 last_bound_was_inclusive = inclusive;
1179 segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((start_bound, current_bound));
1180 } else {
1181 // If the delta from the end bound of the last range is 0 and
1182 // any of the last ending or current starting bound is inclusive,
1183 // we skip the delta because they basically overlap.
1184 if delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 && (last_bound_was_inclusive || inclusive) {
1185 continue;
1186 }
1187 start = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current_bound);
1188 }
1189 }
1190
1191 // If we still have a start bound, but didn't have enough deltas to complete another
1192 // segment, we add an unbounded upperbound.
1193 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start_bound) = start {
1194 segments.pushrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]push().((start_bound, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#));
1195 }
1196
1197 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges# { segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments. }.check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().()
1198 })
1199 }
1200
1201 #[cfg(test)]
1202 pub mod testsrust-analyzer cargo astral-version-ranges 0.1.4 tests/ {
1203 use proptestrust-analyzer cargo proptest 1.8.0 crate/::preluderust-analyzer cargo proptest 1.8.0 prelude/::*;
1204
1205 use superrust-analyzer cargo astral-version-ranges 0.1.4 crate/::*;
1206
1207 fn version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().() -> impl Strategyrust-analyzer cargo proptest 1.8.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.8.0 strategy/traits/Strategy#Value# = u32> {
1208 anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<u32>()
1209 }
1210
1211 proptestrust-analyzer cargo proptest 1.8.0 sugar/proptest!! {
1212
1213 // Testing serde ----------------------------------
1214
1215 #[cfg(feature = "serde")]
1216 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1217 fn serde_round_triprust-analyzer cargo astral-version-ranges 0.1.4 tests/serde_round_trip().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1218 let s = ronrust-analyzer cargo ron 0.12.0 crate/::serrust-analyzer cargo ron 0.12.0 ser/::to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&range).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1219 let r = ronrust-analyzer cargo ron 0.12.0 crate/::derust-analyzer cargo ron 0.12.0 de/::from_strrust-analyzer cargo ron 0.12.0 de/from_str().(&s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1220 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range, r);
1221 }
1222
1223 // Testing negate ----------------------------------
1224
1225 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1226 fn negate_is_differentrust-analyzer cargo astral-version-ranges 0.1.4 tests/negate_is_different().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1227 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().(), range);
1228 }
1229
1230 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1231 fn double_negate_is_identityrust-analyzer cargo astral-version-ranges 0.1.4 tests/double_negate_is_identity().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1232 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().().complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().(), range);
1233 }
1234
1235 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1236 fn negate_contains_oppositerust-analyzer cargo astral-version-ranges 0.1.4 tests/negate_contains_opposite().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1237 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().().containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1238 }
1239
1240 // Testing intersection ----------------------------
1241
1242 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1243 fn intersection_is_symmetricrust-analyzer cargo astral-version-ranges 0.1.4 tests/intersection_is_symmetric().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1244 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2), r2.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r1));
1245 }
1246
1247 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1248 fn intersection_with_any_is_identityrust-analyzer cargo astral-version-ranges 0.1.4 tests/intersection_with_any_is_identity().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1249 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::fullrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]full().().intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&range), range);
1250 }
1251
1252 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1253 fn intersection_with_none_is_nonerust-analyzer cargo astral-version-ranges 0.1.4 tests/intersection_with_none_is_none().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1254 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().().intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&range), Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().());
1255 }
1256
1257 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1258 fn intersection_is_idempotentrust-analyzer cargo astral-version-ranges 0.1.4 tests/intersection_is_idempotent().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1259 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2).intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2), r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2));
1260 }
1261
1262 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1263 fn intersection_is_associativerust-analyzer cargo astral-version-ranges 0.1.4 tests/intersection_is_associative().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r3 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1264 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2).intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r3), r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r3)));
1265 }
1266
1267 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1268 fn intesection_of_complements_is_nonerust-analyzer cargo astral-version-ranges 0.1.4 tests/intesection_of_complements_is_none().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1269 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().().intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&range), Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().());
1270 }
1271
1272 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1273 fn intesection_contains_bothrust-analyzer cargo astral-version-ranges 0.1.4 tests/intesection_contains_both().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1274 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2).containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), r1.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version) && r2.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1275 }
1276
1277 // Testing union -----------------------------------
1278
1279 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1280 fn union_of_complements_is_anyrust-analyzer cargo astral-version-ranges 0.1.4 tests/union_of_complements_is_any().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1281 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().().unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&range), Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::fullrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]full().());
1282 }
1283
1284 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1285 fn union_contains_eitherrust-analyzer cargo astral-version-ranges 0.1.4 tests/union_contains_either().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1286 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&r2).containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), r1.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version) || r2.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1287 }
1288
1289 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1290 fn is_disjoint_through_intersectionrust-analyzer cargo astral-version-ranges 0.1.4 tests/is_disjoint_through_intersection().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1291 let disjoint_def = r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2) == Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().();
1292 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.is_disjointrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]is_disjoint().(&r2), disjoint_def);
1293 }
1294
1295 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1296 fn subset_of_through_intersectionrust-analyzer cargo astral-version-ranges 0.1.4 tests/subset_of_through_intersection().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1297 let disjoint_def = r1.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2) == r1;
1298 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.subset_ofrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]subset_of().(&r2), disjoint_def);
1299 }
1300
1301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1302 fn union_through_intersectionrust-analyzer cargo astral-version-ranges 0.1.4 tests/union_through_intersection().(r1 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), r2 in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().()) {
1303 let union_def = r1
1304 .complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().()
1305 .intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&r2.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().())
1306 .complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().()
1307 .check_invariantsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]check_invariants().();
1308 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&r2), union_def);
1309 }
1310
1311 // Testing contains --------------------------------
1312
1313 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1314 fn always_contains_exactrust-analyzer cargo astral-version-ranges 0.1.4 tests/always_contains_exact().(version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1315 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::<u32>::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(version).containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1316 }
1317
1318 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1319 fn contains_negationrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_negation().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1320 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), range.complementrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]complement().().containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1321 }
1322
1323 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1324 fn contains_intersectionrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_intersection().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1325 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), range.intersectionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]intersection().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(version)) != Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().());
1326 }
1327
1328 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1329 fn contains_bounding_rangerust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_bounding_range().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1330 if range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version) {
1331 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(range.bounding_rangerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]bounding_range().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|b| b.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#contains().(&version)).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false));
1332 }
1333 }
1334
1335 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1336 fn from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 tests/from_range_bounds().(range in anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>)>(), version in version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().()) {
1337 let rv: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<_> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::<u32>::from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]from_range_bounds().(range);
1338 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#contains().(&version), rv.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1339 }
1340
1341 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1342 fn from_range_bounds_round_triprust-analyzer cargo astral-version-ranges 0.1.4 tests/from_range_bounds_round_trip().(range in anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>)>()) {
1343 let rv: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u32> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]from_range_bounds().(range);
1344 let rv2: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u32> = rv.bounding_rangerust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]bounding_range().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]from_range_bounds().::<_, u32>).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().);
1345 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rv, rv2);
1346 }
1347
1348 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1349 fn containsrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), versions in proptestrust-analyzer cargo proptest 1.8.0 crate/::collectionrust-analyzer cargo proptest 1.8.0 collection/::vecrust-analyzer cargo proptest 1.8.0 collection/vec().(version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().(), ..30)) {
1350 for v in versions {
1351 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&v), range.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|s| RangeBoundsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#::containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeBounds#contains().(s, &v)));
1352 }
1353 }
1354
1355 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1356 fn contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_many().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), mut versions in proptestrust-analyzer cargo proptest 1.8.0 crate/::collectionrust-analyzer cargo proptest 1.8.0 collection/::vecrust-analyzer cargo proptest 1.8.0 collection/vec().(version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().(), ..30)) {
1357 versions.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
1358 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(versions.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), range.contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().());
1359 for (a, b) in versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(range.contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().())) {
1360 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(a), b);
1361 }
1362 }
1363
1364 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1365 fn simplifyrust-analyzer cargo astral-version-ranges 0.1.4 tests/simplify().(range in proptest_strategyrust-analyzer cargo astral-version-ranges 0.1.4 proptest_strategy().(), mut versions in proptestrust-analyzer cargo proptest 1.8.0 crate/::collectionrust-analyzer cargo proptest 1.8.0 collection/::vecrust-analyzer cargo proptest 1.8.0 collection/vec().(version_stratrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_strat().(), ..30)) {
1366 versions.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
1367 let simp = range.simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().());
1368
1369 for v in versions {
1370 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&v), simp.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&v));
1371 }
1372 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(simp.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().() <= range.segmentsrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#segments..lenrust-analyzer cargo smallvec 1.15.1 impl#[`SmallVec<A>`]len().())
1373 }
1374
1375 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1376 fn from_iter_validrust-analyzer cargo astral-version-ranges 0.1.4 tests/from_iter_valid().(segments in proptestrust-analyzer cargo proptest 1.8.0 crate/::collectionrust-analyzer cargo proptest 1.8.0 collection/::vecrust-analyzer cargo proptest 1.8.0 collection/vec().(anyrust-analyzer cargo proptest 1.8.0 arbitrary/traits/any().::<(Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<u32>)>(), ..30)) {
1377 let mut expected = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::emptyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]empty().();
1378 for segment in &segments {
1379 expected = expected.unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::from_range_boundsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]from_range_bounds().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().segment));
1380 }
1381 let actual = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::from_iterrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`][`FromIterator<(Bound<V>, Bound<V>)>`]from_iter().(segments.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().());
1382 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual, "{segments:?}");
1383 }
1384 }
1385
1386 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1387 fn contains_many_can_take_ownedrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_many_can_take_owned().() {
1388 let range: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u8> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(1);
1389 let versions = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3];
1390 // Check that iter can be a Cow
1391 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1392 range.contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(),
1393 range
1394 .contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#))
1395 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
1396 );
1397 // Check that iter can be a V
1398 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1399 range.contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(),
1400 range.contains_manyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains_many().(versions.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
1401 );
1402 }
1403
1404 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1405 fn contains_can_take_ownedrust-analyzer cargo astral-version-ranges 0.1.4 tests/contains_can_take_owned().() {
1406 let range: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<u8>> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(1);
1407 let version = 1;
1408
1409 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(version)), range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version));
1410 let range: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(1.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1411 let version = 1.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1412 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().(&version), range.containsrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]contains().("1"));
1413 }
1414
1415 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1416 fn simplify_can_take_ownedrust-analyzer cargo astral-version-ranges 0.1.4 tests/simplify_can_take_owned().() {
1417 let range: Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u8> = Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(1);
1418 let versions = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3];
1419 // Check that iter can be a Cow
1420 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1421 range.simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()),
1422 range.simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#))
1423 );
1424 // Check that iter can be a V
1425 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1426 range.simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().(versions.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()),
1427 range.simplifyrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]simplify().(versions.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().())
1428 );
1429 }
1430
1431 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1432 fn version_ordrust-analyzer cargo astral-version-ranges 0.1.4 tests/version_ord().() {
1433 let versions: &[Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#<u32>] = &[
1434 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::strictly_lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]strictly_lower_than().(1u32),
1435 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::lower_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]lower_than().(1u32),
1436 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(1u32),
1437 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::betweenrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]between().(1u32, 3u32),
1438 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::higher_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]higher_than().(1u32),
1439 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::strictly_higher_thanrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]strictly_higher_than().(1u32),
1440 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(2u32),
1441 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(2u32).unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(3u32)),
1442 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(2u32)
1443 .unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(3u32))
1444 .unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(4u32)),
1445 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(2u32).unionrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]union().(&Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(4u32)),
1446 Rangesrust-analyzer cargo astral-version-ranges 0.1.4 Ranges#::singletonrust-analyzer cargo astral-version-ranges 0.1.4 impl#[`Ranges<V>`]singleton().(3u32),
1447 ];
1448
1449 let mut versions_sorted = versions.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
1450 versions_sorted.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
1451 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(versions_sorted, versions);
1452
1453 // Check that the sorting isn't just stable because we're returning equal.
1454 let mut version_reverse_sorted = versions.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
1455 version_reverse_sorted.reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]reverse().();
1456 version_reverse_sorted.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
1457 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(version_reverse_sorted, versions);
1458 }
1459 }