1use crate::fmt;
2use crate::hash::Hash;
3use crate::marker::Destruct;
4#[lang = "RangeFull"]
40#[doc(alias = "..")]
41#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::marker::Copy for RangeFull { }Copy, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::hash::Hash for RangeFull {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {}
}Hash)]
42#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl const crate::clone::Clone for RangeFull {
#[inline]
fn clone(&self) -> RangeFull { *self }
}Clone, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl const crate::default::Default for RangeFull {
#[inline]
fn default() -> RangeFull { RangeFull {} }
}Default, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl const crate::cmp::Eq for RangeFull {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl const crate::cmp::PartialEq for RangeFull {
#[inline]
fn eq(&self, other: &RangeFull) -> bool { true }
}PartialEq)]
43#[stable(feature = "rust1", since = "1.0.0")]
44pub struct RangeFull;
45
46#[stable(feature = "rust1", since = "1.0.0")]
47impl fmt::Debug for RangeFull {
48 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
49 fmt.write_fmt(format_args!(".."))write!(fmt, "..")
50 }
51}
52
53#[lang = "Range"]
78#[doc(alias = "..")]
79#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::Eq> crate::cmp::Eq for Range<Idx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<Idx>;
}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::hash::Hash> crate::hash::Hash for Range<Idx> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.start, state);
crate::hash::Hash::hash(&self.end, state)
}
}Hash)]
80#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::clone::Clone> const crate::clone::Clone for
Range<Idx> {
#[inline]
fn clone(&self) -> Range<Idx> {
Range {
start: crate::clone::Clone::clone(&self.start),
end: crate::clone::Clone::clone(&self.end),
}
}
}Clone, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::default::Default> const crate::default::Default for
Range<Idx> {
#[inline]
fn default() -> Range<Idx> {
Range {
start: crate::default::Default::default(),
end: crate::default::Default::default(),
}
}
}Default, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::cmp::PartialEq> const crate::cmp::PartialEq for
Range<Idx> {
#[inline]
fn eq(&self, other: &Range<Idx>) -> bool {
self.start == other.start && self.end == other.end
}
}PartialEq)] #[stable(feature = "rust1", since = "1.0.0")]
82pub struct Range<Idx> {
83 #[stable(feature = "rust1", since = "1.0.0")]
85 pub start: Idx,
86 #[stable(feature = "rust1", since = "1.0.0")]
88 pub end: Idx,
89}
90
91#[stable(feature = "rust1", since = "1.0.0")]
92impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
93 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
94 self.start.fmt(fmt)?;
95 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
96 self.end.fmt(fmt)?;
97 Ok(())
98 }
99}
100
101impl<Idx: PartialOrd<Idx>> Range<Idx> {
102 #[inline]
121 #[stable(feature = "range_contains", since = "1.35.0")]
122 #[rustc_const_unstable(feature = "const_range", issue = "none")]
123 pub const fn contains<U>(&self, item: &U) -> bool
124 where
125 Idx: [const] PartialOrd<U>,
126 U: ?Sized + [const] PartialOrd<Idx>,
127 {
128 <Self as RangeBounds<Idx>>::contains(self, item)
129 }
130
131 #[inline]
149 #[stable(feature = "range_is_empty", since = "1.47.0")]
150 #[rustc_const_unstable(feature = "const_range", issue = "none")]
151 pub const fn is_empty(&self) -> bool
152 where
153 Idx: [const] PartialOrd<Idx>,
154 {
155 !(self.start < self.end)
156 }
157}
158
159#[lang = "RangeFrom"]
193#[doc(alias = "..")]
194#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::Eq> crate::cmp::Eq for RangeFrom<Idx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<Idx>;
}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::hash::Hash> crate::hash::Hash for RangeFrom<Idx> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.start, state)
}
}Hash)]
195#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::clone::Clone> const crate::clone::Clone for
RangeFrom<Idx> {
#[inline]
fn clone(&self) -> RangeFrom<Idx> {
RangeFrom { start: crate::clone::Clone::clone(&self.start) }
}
}Clone, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::cmp::PartialEq> const crate::cmp::PartialEq for
RangeFrom<Idx> {
#[inline]
fn eq(&self, other: &RangeFrom<Idx>) -> bool { self.start == other.start }
}PartialEq)] #[stable(feature = "rust1", since = "1.0.0")]
197pub struct RangeFrom<Idx> {
198 #[stable(feature = "rust1", since = "1.0.0")]
200 pub start: Idx,
201}
202
203#[stable(feature = "rust1", since = "1.0.0")]
204impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
205 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
206 self.start.fmt(fmt)?;
207 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
208 Ok(())
209 }
210}
211
212impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
213 #[inline]
227 #[stable(feature = "range_contains", since = "1.35.0")]
228 #[rustc_const_unstable(feature = "const_range", issue = "none")]
229 pub const fn contains<U>(&self, item: &U) -> bool
230 where
231 Idx: [const] PartialOrd<U>,
232 U: ?Sized + [const] PartialOrd<Idx>,
233 {
234 <Self as RangeBounds<Idx>>::contains(self, item)
235 }
236}
237
238#[lang = "RangeTo"]
277#[doc(alias = "..")]
278#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::marker::Copy> crate::marker::Copy for RangeTo<Idx> { }Copy, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::Eq> crate::cmp::Eq for RangeTo<Idx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<Idx>;
}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::hash::Hash> crate::hash::Hash for RangeTo<Idx> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.end, state)
}
}Hash)]
279#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::clone::Clone> const crate::clone::Clone for
RangeTo<Idx> {
#[inline]
fn clone(&self) -> RangeTo<Idx> {
RangeTo { end: crate::clone::Clone::clone(&self.end) }
}
}Clone, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: [const] crate::cmp::PartialEq> const crate::cmp::PartialEq for
RangeTo<Idx> {
#[inline]
fn eq(&self, other: &RangeTo<Idx>) -> bool { self.end == other.end }
}PartialEq)]
280#[stable(feature = "rust1", since = "1.0.0")]
281pub struct RangeTo<Idx> {
282 #[stable(feature = "rust1", since = "1.0.0")]
284 pub end: Idx,
285}
286
287#[stable(feature = "rust1", since = "1.0.0")]
288impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
289 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
290 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
291 self.end.fmt(fmt)?;
292 Ok(())
293 }
294}
295
296impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
297 #[inline]
311 #[stable(feature = "range_contains", since = "1.35.0")]
312 #[rustc_const_unstable(feature = "const_range", issue = "none")]
313 pub const fn contains<U>(&self, item: &U) -> bool
314 where
315 Idx: [const] PartialOrd<U>,
316 U: ?Sized + [const] PartialOrd<Idx>,
317 {
318 <Self as RangeBounds<Idx>>::contains(self, item)
319 }
320}
321
322#[lang = "RangeInclusive"]
353#[doc(alias = "..=")]
354#[derive(#[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::clone::Clone> crate::clone::Clone for RangeInclusive<Idx> {
#[inline]
fn clone(&self) -> RangeInclusive<Idx> {
RangeInclusive {
start: crate::clone::Clone::clone(&self.start),
end: crate::clone::Clone::clone(&self.end),
exhausted: crate::clone::Clone::clone(&self.exhausted),
}
}
}Clone, #[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::hash::Hash> crate::hash::Hash for RangeInclusive<Idx> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.start, state);
crate::hash::Hash::hash(&self.end, state);
crate::hash::Hash::hash(&self.exhausted, state)
}
}Hash)]
355#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: [const] crate::cmp::Eq> const crate::cmp::Eq for RangeInclusive<Idx>
{
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<Idx>;
let _: crate::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: [const] crate::cmp::PartialEq> const crate::cmp::PartialEq for
RangeInclusive<Idx> {
#[inline]
fn eq(&self, other: &RangeInclusive<Idx>) -> bool {
self.exhausted == other.exhausted && self.start == other.start &&
self.end == other.end
}
}PartialEq)] #[stable(feature = "inclusive_range", since = "1.26.0")]
357pub struct RangeInclusive<Idx> {
358 pub(crate) start: Idx,
364 pub(crate) end: Idx,
365
366 pub(crate) exhausted: bool,
373}
374
375impl<Idx> RangeInclusive<Idx> {
376 #[lang = "range_inclusive_new"]
386 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
387 #[inline]
388 #[rustc_promotable]
389 #[rustc_const_stable(feature = "const_range_new", since = "1.32.0")]
390 pub const fn new(start: Idx, end: Idx) -> Self {
391 Self { start, end, exhausted: false }
392 }
393
394 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
413 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
414 #[inline]
415 pub const fn start(&self) -> &Idx {
416 &self.start
417 }
418
419 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
438 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
439 #[inline]
440 pub const fn end(&self) -> &Idx {
441 &self.end
442 }
443
444 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
455 #[inline]
456 #[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
457 pub const fn into_inner(self) -> (Idx, Idx) {
458 (self.start, self.end)
459 }
460}
461
462impl RangeInclusive<usize> {
463 #[inline]
466 pub(crate) const fn into_slice_range(self) -> Range<usize> {
467 let exclusive_end = self.end + 1;
471 let start = if self.exhausted { exclusive_end } else { self.start };
472 start..exclusive_end
473 }
474}
475
476#[stable(feature = "inclusive_range", since = "1.26.0")]
477impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
478 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
479 self.start.fmt(fmt)?;
480 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
481 self.end.fmt(fmt)?;
482 if self.exhausted {
483 fmt.write_fmt(format_args!(" (exhausted)"))write!(fmt, " (exhausted)")?;
484 }
485 Ok(())
486 }
487}
488
489impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
490 #[inline]
520 #[stable(feature = "range_contains", since = "1.35.0")]
521 #[rustc_const_unstable(feature = "const_range", issue = "none")]
522 pub const fn contains<U>(&self, item: &U) -> bool
523 where
524 Idx: [const] PartialOrd<U>,
525 U: ?Sized + [const] PartialOrd<Idx>,
526 {
527 <Self as RangeBounds<Idx>>::contains(self, item)
528 }
529
530 #[stable(feature = "range_is_empty", since = "1.47.0")]
557 #[inline]
558 #[rustc_const_unstable(feature = "const_range", issue = "none")]
559 pub const fn is_empty(&self) -> bool
560 where
561 Idx: [const] PartialOrd,
562 {
563 self.exhausted || !(self.start <= self.end)
564 }
565}
566
567#[lang = "RangeToInclusive"]
606#[doc(alias = "..=")]
607#[derive(#[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::marker::Copy> crate::marker::Copy for RangeToInclusive<Idx> {
}Copy, #[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::hash::Hash> crate::hash::Hash for RangeToInclusive<Idx> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
crate::hash::Hash::hash(&self.end, state)
}
}Hash)]
608#[derive(#[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::clone::Clone> crate::clone::Clone for RangeToInclusive<Idx> {
#[inline]
fn clone(&self) -> RangeToInclusive<Idx> {
RangeToInclusive { end: crate::clone::Clone::clone(&self.end) }
}
}Clone, #[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::cmp::PartialEq> crate::cmp::PartialEq for
RangeToInclusive<Idx> {
#[inline]
fn eq(&self, other: &RangeToInclusive<Idx>) -> bool {
self.end == other.end
}
}PartialEq, #[automatically_derived]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::cmp::Eq> crate::cmp::Eq for RangeToInclusive<Idx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<Idx>;
}
}Eq)]
609#[stable(feature = "inclusive_range", since = "1.26.0")]
610pub struct RangeToInclusive<Idx> {
611 #[stable(feature = "inclusive_range", since = "1.26.0")]
613 pub end: Idx,
614}
615
616#[stable(feature = "inclusive_range", since = "1.26.0")]
617impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
618 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
619 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
620 self.end.fmt(fmt)?;
621 Ok(())
622 }
623}
624
625impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
626 #[inline]
640 #[stable(feature = "range_contains", since = "1.35.0")]
641 #[rustc_const_unstable(feature = "const_range", issue = "none")]
642 pub const fn contains<U>(&self, item: &U) -> bool
643 where
644 Idx: [const] PartialOrd<U>,
645 U: ?Sized + [const] PartialOrd<Idx>,
646 {
647 <Self as RangeBounds<Idx>>::contains(self, item)
648 }
649}
650
651#[stable(feature = "collections_bound", since = "1.17.0")]
690#[derive(#[automatically_derived]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: crate::marker::Copy> crate::marker::Copy for Bound<T> { }Copy, #[automatically_derived]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: crate::fmt::Debug> crate::fmt::Debug for Bound<T> {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
match self {
Bound::Included(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f,
"Included", &__self_0),
Bound::Excluded(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f,
"Excluded", &__self_0),
Bound::Unbounded =>
crate::fmt::Formatter::write_str(f, "Unbounded"),
}
}
}Debug, #[automatically_derived]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: crate::hash::Hash> crate::hash::Hash for Bound<T> {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = crate::intrinsics::discriminant_value(self);
crate::hash::Hash::hash(&__self_discr, state);
match self {
Bound::Included(__self_0) =>
crate::hash::Hash::hash(__self_0, state),
Bound::Excluded(__self_0) =>
crate::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
691#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: [const] crate::clone::Clone> const crate::clone::Clone for Bound<T> {
#[inline]
fn clone(&self) -> Bound<T> {
match self {
Bound::Included(__self_0) =>
Bound::Included(crate::clone::Clone::clone(__self_0)),
Bound::Excluded(__self_0) =>
Bound::Excluded(crate::clone::Clone::clone(__self_0)),
Bound::Unbounded => Bound::Unbounded,
}
}
}Clone, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: [const] crate::cmp::Eq> const crate::cmp::Eq for Bound<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) { let _: crate::cmp::AssertParamIsEq<T>; }
}Eq, #[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: [const] crate::cmp::PartialEq> const crate::cmp::PartialEq for
Bound<T> {
#[inline]
fn eq(&self, other: &Bound<T>) -> bool {
let __self_discr = crate::intrinsics::discriminant_value(self);
let __arg1_discr = crate::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(Bound::Included(__self_0), Bound::Included(__arg1_0)) =>
__self_0 == __arg1_0,
(Bound::Excluded(__self_0), Bound::Excluded(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
692pub enum Bound<T> {
693 #[stable(feature = "collections_bound", since = "1.17.0")]
695 Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
696 #[stable(feature = "collections_bound", since = "1.17.0")]
698 Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
699 #[stable(feature = "collections_bound", since = "1.17.0")]
701 Unbounded,
702}
703
704impl<T> Bound<T> {
705 #[inline]
707 #[stable(feature = "bound_as_ref_shared", since = "1.65.0")]
708 #[rustc_const_unstable(feature = "const_range", issue = "none")]
709 pub const fn as_ref(&self) -> Bound<&T> {
710 match *self {
711 Included(ref x) => Included(x),
712 Excluded(ref x) => Excluded(x),
713 Unbounded => Unbounded,
714 }
715 }
716
717 #[inline]
719 #[unstable(feature = "bound_as_ref", issue = "80996")]
720 pub const fn as_mut(&mut self) -> Bound<&mut T> {
721 match *self {
722 Included(ref mut x) => Included(x),
723 Excluded(ref mut x) => Excluded(x),
724 Unbounded => Unbounded,
725 }
726 }
727
728 #[inline]
750 #[stable(feature = "bound_map", since = "1.77.0")]
751 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U> {
752 match self {
753 Unbounded => Unbounded,
754 Included(x) => Included(f(x)),
755 Excluded(x) => Excluded(f(x)),
756 }
757 }
758}
759
760impl<T: Copy> Bound<&T> {
761 #[unstable(feature = "bound_copied", issue = "145966")]
775 #[must_use]
776 pub const fn copied(self) -> Bound<T> {
777 match self {
778 Bound::Unbounded => Bound::Unbounded,
779 Bound::Included(x) => Bound::Included(*x),
780 Bound::Excluded(x) => Bound::Excluded(*x),
781 }
782 }
783}
784
785impl<T: Clone> Bound<&T> {
786 #[must_use = "`self` will be dropped if the result is not used"]
801 #[stable(feature = "bound_cloned", since = "1.55.0")]
802 #[rustc_const_unstable(feature = "const_range", issue = "none")]
803 pub const fn cloned(self) -> Bound<T>
804 where
805 T: [const] Clone,
806 {
807 match self {
808 Bound::Unbounded => Bound::Unbounded,
809 Bound::Included(x) => Bound::Included(x.clone()),
810 Bound::Excluded(x) => Bound::Excluded(x.clone()),
811 }
812 }
813}
814
815#[stable(feature = "collections_range", since = "1.28.0")]
818#[rustc_diagnostic_item = "RangeBounds"]
819#[rustc_const_unstable(feature = "const_range", issue = "none")]
820pub const trait RangeBounds<T: ?Sized> {
821 #[stable(feature = "collections_range", since = "1.28.0")]
835 fn start_bound(&self) -> Bound<&T>;
836
837 #[stable(feature = "collections_range", since = "1.28.0")]
851 fn end_bound(&self) -> Bound<&T>;
852
853 #[inline]
867 #[stable(feature = "range_contains", since = "1.35.0")]
868 fn contains<U>(&self, item: &U) -> bool
869 where
870 T: [const] PartialOrd<U>,
871 U: ?Sized + [const] PartialOrd<T>,
872 {
873 (match self.start_bound() {
874 Included(start) => start <= item,
875 Excluded(start) => start < item,
876 Unbounded => true,
877 }) && (match self.end_bound() {
878 Included(end) => item <= end,
879 Excluded(end) => item < end,
880 Unbounded => true,
881 })
882 }
883
884 #[unstable(feature = "range_bounds_is_empty", issue = "137300")]
936 fn is_empty(&self) -> bool
937 where
938 T: [const] PartialOrd,
939 {
940 !match (self.start_bound(), self.end_bound()) {
941 (Unbounded, _) | (_, Unbounded) => true,
942 (Included(start), Excluded(end))
943 | (Excluded(start), Included(end))
944 | (Excluded(start), Excluded(end)) => start < end,
945 (Included(start), Included(end)) => start <= end,
946 }
947 }
948}
949
950#[unstable(feature = "range_into_bounds", issue = "136903")]
956#[rustc_const_unstable(feature = "const_range", issue = "none")]
957pub const trait IntoBounds<T>: [const] RangeBounds<T> {
958 fn into_bounds(self) -> (Bound<T>, Bound<T>);
972
973 fn intersect<R>(self, other: R) -> (Bound<T>, Bound<T>)
1001 where
1002 Self: Sized,
1003 T: [const] Ord + [const] Destruct,
1004 R: Sized + [const] IntoBounds<T>,
1005 {
1006 let (self_start, self_end) = IntoBounds::into_bounds(self);
1007 let (other_start, other_end) = IntoBounds::into_bounds(other);
1008
1009 let start = match (self_start, other_start) {
1010 (Included(a), Included(b)) => Included(Ord::max(a, b)),
1011 (Excluded(a), Excluded(b)) => Excluded(Ord::max(a, b)),
1012 (Unbounded, Unbounded) => Unbounded,
1013
1014 (x, Unbounded) | (Unbounded, x) => x,
1015
1016 (Included(i), Excluded(e)) | (Excluded(e), Included(i)) => {
1017 if i > e {
1018 Included(i)
1019 } else {
1020 Excluded(e)
1021 }
1022 }
1023 };
1024 let end = match (self_end, other_end) {
1025 (Included(a), Included(b)) => Included(Ord::min(a, b)),
1026 (Excluded(a), Excluded(b)) => Excluded(Ord::min(a, b)),
1027 (Unbounded, Unbounded) => Unbounded,
1028
1029 (x, Unbounded) | (Unbounded, x) => x,
1030
1031 (Included(i), Excluded(e)) | (Excluded(e), Included(i)) => {
1032 if i < e {
1033 Included(i)
1034 } else {
1035 Excluded(e)
1036 }
1037 }
1038 };
1039
1040 (start, end)
1041 }
1042}
1043
1044use self::Bound::{Excluded, Included, Unbounded};
1045
1046#[stable(feature = "collections_range", since = "1.28.0")]
1047#[rustc_const_unstable(feature = "const_range", issue = "none")]
1048impl<T: ?Sized> const RangeBounds<T> for RangeFull {
1049 fn start_bound(&self) -> Bound<&T> {
1050 Unbounded
1051 }
1052 fn end_bound(&self) -> Bound<&T> {
1053 Unbounded
1054 }
1055}
1056
1057#[unstable(feature = "range_into_bounds", issue = "136903")]
1058#[rustc_const_unstable(feature = "const_range", issue = "none")]
1059impl<T> const IntoBounds<T> for RangeFull {
1060 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1061 (Unbounded, Unbounded)
1062 }
1063}
1064
1065#[stable(feature = "collections_range", since = "1.28.0")]
1066#[rustc_const_unstable(feature = "const_range", issue = "none")]
1067impl<T> const RangeBounds<T> for RangeFrom<T> {
1068 fn start_bound(&self) -> Bound<&T> {
1069 Included(&self.start)
1070 }
1071 fn end_bound(&self) -> Bound<&T> {
1072 Unbounded
1073 }
1074}
1075
1076#[unstable(feature = "range_into_bounds", issue = "136903")]
1077#[rustc_const_unstable(feature = "const_range", issue = "none")]
1078impl<T> const IntoBounds<T> for RangeFrom<T> {
1079 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1080 (Included(self.start), Unbounded)
1081 }
1082}
1083
1084#[stable(feature = "collections_range", since = "1.28.0")]
1085#[rustc_const_unstable(feature = "const_range", issue = "none")]
1086impl<T> const RangeBounds<T> for RangeTo<T> {
1087 fn start_bound(&self) -> Bound<&T> {
1088 Unbounded
1089 }
1090 fn end_bound(&self) -> Bound<&T> {
1091 Excluded(&self.end)
1092 }
1093}
1094
1095#[unstable(feature = "range_into_bounds", issue = "136903")]
1096#[rustc_const_unstable(feature = "const_range", issue = "none")]
1097impl<T> const IntoBounds<T> for RangeTo<T> {
1098 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1099 (Unbounded, Excluded(self.end))
1100 }
1101}
1102
1103#[stable(feature = "collections_range", since = "1.28.0")]
1104#[rustc_const_unstable(feature = "const_range", issue = "none")]
1105impl<T> const RangeBounds<T> for Range<T> {
1106 fn start_bound(&self) -> Bound<&T> {
1107 Included(&self.start)
1108 }
1109 fn end_bound(&self) -> Bound<&T> {
1110 Excluded(&self.end)
1111 }
1112}
1113
1114#[unstable(feature = "range_into_bounds", issue = "136903")]
1115#[rustc_const_unstable(feature = "const_range", issue = "none")]
1116impl<T> const IntoBounds<T> for Range<T> {
1117 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1118 (Included(self.start), Excluded(self.end))
1119 }
1120}
1121
1122#[stable(feature = "collections_range", since = "1.28.0")]
1123#[rustc_const_unstable(feature = "const_range", issue = "none")]
1124impl<T> const RangeBounds<T> for RangeInclusive<T> {
1125 fn start_bound(&self) -> Bound<&T> {
1126 Included(&self.start)
1127 }
1128 fn end_bound(&self) -> Bound<&T> {
1129 if self.exhausted {
1130 Excluded(&self.end)
1133 } else {
1134 Included(&self.end)
1135 }
1136 }
1137}
1138
1139#[unstable(feature = "range_into_bounds", issue = "136903")]
1140#[rustc_const_unstable(feature = "const_range", issue = "none")]
1141impl<T> const IntoBounds<T> for RangeInclusive<T> {
1142 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1143 (
1144 Included(self.start),
1145 if self.exhausted {
1146 Excluded(self.end)
1149 } else {
1150 Included(self.end)
1151 },
1152 )
1153 }
1154}
1155
1156#[stable(feature = "collections_range", since = "1.28.0")]
1157#[rustc_const_unstable(feature = "const_range", issue = "none")]
1158impl<T> const RangeBounds<T> for RangeToInclusive<T> {
1159 fn start_bound(&self) -> Bound<&T> {
1160 Unbounded
1161 }
1162 fn end_bound(&self) -> Bound<&T> {
1163 Included(&self.end)
1164 }
1165}
1166
1167#[unstable(feature = "range_into_bounds", issue = "136903")]
1168#[rustc_const_unstable(feature = "const_range", issue = "none")]
1169impl<T> const IntoBounds<T> for RangeToInclusive<T> {
1170 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1171 (Unbounded, Included(self.end))
1172 }
1173}
1174
1175#[stable(feature = "collections_range", since = "1.28.0")]
1176#[rustc_const_unstable(feature = "const_range", issue = "none")]
1177impl<T> const RangeBounds<T> for (Bound<T>, Bound<T>) {
1178 fn start_bound(&self) -> Bound<&T> {
1179 match *self {
1180 (Included(ref start), _) => Included(start),
1181 (Excluded(ref start), _) => Excluded(start),
1182 (Unbounded, _) => Unbounded,
1183 }
1184 }
1185
1186 fn end_bound(&self) -> Bound<&T> {
1187 match *self {
1188 (_, Included(ref end)) => Included(end),
1189 (_, Excluded(ref end)) => Excluded(end),
1190 (_, Unbounded) => Unbounded,
1191 }
1192 }
1193}
1194
1195#[unstable(feature = "range_into_bounds", issue = "136903")]
1196#[rustc_const_unstable(feature = "const_range", issue = "none")]
1197impl<T> const IntoBounds<T> for (Bound<T>, Bound<T>) {
1198 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1199 self
1200 }
1201}
1202
1203#[stable(feature = "collections_range", since = "1.28.0")]
1204#[rustc_const_unstable(feature = "const_range", issue = "none")]
1205impl<'a, T: ?Sized + 'a> const RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
1206 fn start_bound(&self) -> Bound<&T> {
1207 self.0
1208 }
1209
1210 fn end_bound(&self) -> Bound<&T> {
1211 self.1
1212 }
1213}
1214
1215#[stable(feature = "collections_range", since = "1.28.0")]
1222#[rustc_const_unstable(feature = "const_range", issue = "none")]
1223impl<T> const RangeBounds<T> for RangeFrom<&T> {
1224 fn start_bound(&self) -> Bound<&T> {
1225 Included(self.start)
1226 }
1227 fn end_bound(&self) -> Bound<&T> {
1228 Unbounded
1229 }
1230}
1231
1232#[stable(feature = "collections_range", since = "1.28.0")]
1239#[rustc_const_unstable(feature = "const_range", issue = "none")]
1240impl<T> const RangeBounds<T> for RangeTo<&T> {
1241 fn start_bound(&self) -> Bound<&T> {
1242 Unbounded
1243 }
1244 fn end_bound(&self) -> Bound<&T> {
1245 Excluded(self.end)
1246 }
1247}
1248
1249#[stable(feature = "collections_range", since = "1.28.0")]
1256#[rustc_const_unstable(feature = "const_range", issue = "none")]
1257impl<T> const RangeBounds<T> for Range<&T> {
1258 fn start_bound(&self) -> Bound<&T> {
1259 Included(self.start)
1260 }
1261 fn end_bound(&self) -> Bound<&T> {
1262 Excluded(self.end)
1263 }
1264}
1265
1266#[stable(feature = "collections_range", since = "1.28.0")]
1273#[rustc_const_unstable(feature = "const_range", issue = "none")]
1274impl<T> const RangeBounds<T> for RangeInclusive<&T> {
1275 fn start_bound(&self) -> Bound<&T> {
1276 Included(self.start)
1277 }
1278 fn end_bound(&self) -> Bound<&T> {
1279 Included(self.end)
1280 }
1281}
1282
1283#[stable(feature = "collections_range", since = "1.28.0")]
1290#[rustc_const_unstable(feature = "const_range", issue = "none")]
1291impl<T> const RangeBounds<T> for RangeToInclusive<&T> {
1292 fn start_bound(&self) -> Bound<&T> {
1293 Unbounded
1294 }
1295 fn end_bound(&self) -> Bound<&T> {
1296 Included(self.end)
1297 }
1298}
1299
1300#[unstable(feature = "one_sided_range", issue = "69780")]
1303#[allow(missing_debug_implementations)]
1304pub enum OneSidedRangeBound {
1305 StartInclusive,
1307 End,
1309 EndInclusive,
1311}
1312
1313#[unstable(feature = "one_sided_range", issue = "69780")]
1320#[rustc_const_unstable(feature = "const_range", issue = "none")]
1321pub const trait OneSidedRange<T>: RangeBounds<T> {
1322 fn bound(self) -> (OneSidedRangeBound, T);
1325}
1326
1327#[unstable(feature = "one_sided_range", issue = "69780")]
1328#[rustc_const_unstable(feature = "const_range", issue = "none")]
1329impl<T> const OneSidedRange<T> for RangeTo<T>
1330where
1331 Self: RangeBounds<T>,
1332{
1333 fn bound(self) -> (OneSidedRangeBound, T) {
1334 (OneSidedRangeBound::End, self.end)
1335 }
1336}
1337
1338#[unstable(feature = "one_sided_range", issue = "69780")]
1339#[rustc_const_unstable(feature = "const_range", issue = "none")]
1340impl<T> const OneSidedRange<T> for RangeFrom<T>
1341where
1342 Self: RangeBounds<T>,
1343{
1344 fn bound(self) -> (OneSidedRangeBound, T) {
1345 (OneSidedRangeBound::StartInclusive, self.start)
1346 }
1347}
1348
1349#[unstable(feature = "one_sided_range", issue = "69780")]
1350#[rustc_const_unstable(feature = "const_range", issue = "none")]
1351impl<T> const OneSidedRange<T> for RangeToInclusive<T>
1352where
1353 Self: RangeBounds<T>,
1354{
1355 fn bound(self) -> (OneSidedRangeBound, T) {
1356 (OneSidedRangeBound::EndInclusive, self.end)
1357 }
1358}