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")]
#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
const unsafe impl crate::clone::TrivialClone for RangeFull { }
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl 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")]
const impl 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")]
const impl crate::cmp::Eq for RangeFull {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::marker::StructuralPartialEq for RangeFull { }
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl 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")]
const impl<Idx: [const] crate::clone::Clone> 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")]
const impl<Idx: [const] crate::default::Default> 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]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
Range<Idx> {
}
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::cmp::PartialEq> 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 #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")]
152 pub const fn is_empty(&self) -> bool
153 where
154 Idx: [const] PartialOrd<Idx>,
155 {
156 !(self.start < self.end)
157 }
158}
159
160#[lang = "RangeFrom"]
194#[doc(alias = "..")]
195#[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)]
196#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::clone::Clone> crate::clone::Clone for
RangeFrom<Idx> {
#[inline]
fn clone(&self) -> RangeFrom<Idx> {
RangeFrom { start: crate::clone::Clone::clone(&self.start) }
}
}Clone, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
RangeFrom<Idx> {
}
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::cmp::PartialEq> 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")]
198pub struct RangeFrom<Idx> {
199 #[stable(feature = "rust1", since = "1.0.0")]
201 pub start: Idx,
202}
203
204#[stable(feature = "rust1", since = "1.0.0")]
205impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
206 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
207 self.start.fmt(fmt)?;
208 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
209 Ok(())
210 }
211}
212
213impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
214 #[inline]
228 #[stable(feature = "range_contains", since = "1.35.0")]
229 #[rustc_const_unstable(feature = "const_range", issue = "none")]
230 pub const fn contains<U>(&self, item: &U) -> bool
231 where
232 Idx: [const] PartialOrd<U>,
233 U: ?Sized + [const] PartialOrd<Idx>,
234 {
235 <Self as RangeBounds<Idx>>::contains(self, item)
236 }
237}
238
239#[lang = "RangeTo"]
278#[doc(alias = "..")]
279#[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)]
280#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::clone::Clone> crate::clone::Clone for
RangeTo<Idx> {
#[inline]
fn clone(&self) -> RangeTo<Idx> {
RangeTo { end: crate::clone::Clone::clone(&self.end) }
}
}Clone, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl<Idx: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
RangeTo<Idx> {
}
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::cmp::PartialEq> crate::cmp::PartialEq for
RangeTo<Idx> {
#[inline]
fn eq(&self, other: &RangeTo<Idx>) -> bool { self.end == other.end }
}PartialEq)]
281#[stable(feature = "rust1", since = "1.0.0")]
282pub struct RangeTo<Idx> {
283 #[stable(feature = "rust1", since = "1.0.0")]
285 pub end: Idx,
286}
287
288#[stable(feature = "rust1", since = "1.0.0")]
289impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
290 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
291 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
292 self.end.fmt(fmt)?;
293 Ok(())
294 }
295}
296
297impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
298 #[inline]
312 #[stable(feature = "range_contains", since = "1.35.0")]
313 #[rustc_const_unstable(feature = "const_range", issue = "none")]
314 pub const fn contains<U>(&self, item: &U) -> bool
315 where
316 Idx: [const] PartialOrd<U>,
317 U: ?Sized + [const] PartialOrd<Idx>,
318 {
319 <Self as RangeBounds<Idx>>::contains(self, item)
320 }
321}
322
323#[lang = "RangeInclusive"]
354#[doc(alias = "..=")]
355#[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)]
356#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "inclusive_range", since = "1.26.0")]
const impl<Idx: [const] crate::cmp::Eq> 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]
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
RangeInclusive<Idx> {
}
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "inclusive_range", since = "1.26.0")]
const impl<Idx: [const] crate::cmp::PartialEq> 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")]
358pub struct RangeInclusive<Idx> {
359 pub(crate) start: Idx,
365 pub(crate) end: Idx,
366
367 pub(crate) exhausted: bool,
379}
380
381impl<Idx> RangeInclusive<Idx> {
382 #[lang = "range_inclusive_new"]
392 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
393 #[inline]
394 #[rustc_promotable]
395 #[rustc_const_stable(feature = "const_range_new", since = "1.32.0")]
396 pub const fn new(start: Idx, end: Idx) -> Self {
397 Self { start, end, exhausted: false }
398 }
399
400 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
419 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
420 #[inline]
421 pub const fn start(&self) -> &Idx {
422 &self.start
423 }
424
425 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
444 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
445 #[inline]
446 pub const fn end(&self) -> &Idx {
447 &self.end
448 }
449
450 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
461 #[inline]
462 #[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
463 pub const fn into_inner(self) -> (Idx, Idx) {
464 (self.start, self.end)
465 }
466}
467
468impl RangeInclusive<usize> {
469 #[inline]
472 pub(crate) const fn into_slice_range(self) -> Range<usize> {
473 let exclusive_end = self.end + 1;
484 let start = if self.exhausted { exclusive_end } else { self.start };
485 start..exclusive_end
486 }
487}
488
489#[stable(feature = "inclusive_range", since = "1.26.0")]
490impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
491 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
492 self.start.fmt(fmt)?;
493 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
494 self.end.fmt(fmt)?;
495 if self.exhausted {
496 fmt.write_fmt(format_args!(" (exhausted)"))write!(fmt, " (exhausted)")?;
497 }
498 Ok(())
499 }
500}
501
502impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
503 #[inline]
533 #[stable(feature = "range_contains", since = "1.35.0")]
534 #[rustc_const_unstable(feature = "const_range", issue = "none")]
535 pub const fn contains<U>(&self, item: &U) -> bool
536 where
537 Idx: [const] PartialOrd<U>,
538 U: ?Sized + [const] PartialOrd<Idx>,
539 {
540 <Self as RangeBounds<Idx>>::contains(self, item)
541 }
542
543 #[stable(feature = "range_is_empty", since = "1.47.0")]
570 #[inline]
571 #[rustc_const_unstable(feature = "const_range", issue = "none")]
572 #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")]
573 pub const fn is_empty(&self) -> bool
574 where
575 Idx: [const] PartialOrd,
576 {
577 self.exhausted || !(self.start <= self.end)
578 }
579}
580
581#[lang = "RangeToInclusive"]
620#[doc(alias = "..=")]
621#[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)]
622#[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::marker::StructuralPartialEq for
RangeToInclusive<Idx> {
}
#[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)]
623#[stable(feature = "inclusive_range", since = "1.26.0")]
624pub struct RangeToInclusive<Idx> {
625 #[stable(feature = "inclusive_range", since = "1.26.0")]
627 pub end: Idx,
628}
629
630#[stable(feature = "inclusive_range", since = "1.26.0")]
631impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
632 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
633 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
634 self.end.fmt(fmt)?;
635 Ok(())
636 }
637}
638
639impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
640 #[inline]
654 #[stable(feature = "range_contains", since = "1.35.0")]
655 #[rustc_const_unstable(feature = "const_range", issue = "none")]
656 pub const fn contains<U>(&self, item: &U) -> bool
657 where
658 Idx: [const] PartialOrd<U>,
659 U: ?Sized + [const] PartialOrd<Idx>,
660 {
661 <Self as RangeBounds<Idx>>::contains(self, item)
662 }
663}
664
665#[stable(feature = "collections_bound", since = "1.17.0")]
704#[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)]
705#[derive_const(#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "collections_bound", since = "1.17.0")]
const impl<T: [const] crate::clone::Clone> 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")]
const impl<T: [const] crate::cmp::Eq> 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]
#[stable(feature = "collections_bound", since = "1.17.0")]
impl<T: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for Bound<T>
{
}
#[automatically_derived]
#[rustc_const_unstable(feature = "derive_const", issue = "118304")]
#[stable(feature = "collections_bound", since = "1.17.0")]
const impl<T: [const] crate::cmp::PartialEq> 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)]
706pub enum Bound<T> {
707 #[stable(feature = "collections_bound", since = "1.17.0")]
709 Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
710 #[stable(feature = "collections_bound", since = "1.17.0")]
712 Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
713 #[stable(feature = "collections_bound", since = "1.17.0")]
715 Unbounded,
716}
717
718impl<T> Bound<T> {
719 #[inline]
721 #[stable(feature = "bound_as_ref_shared", since = "1.65.0")]
722 #[rustc_const_unstable(feature = "const_range", issue = "none")]
723 pub const fn as_ref(&self) -> Bound<&T> {
724 match *self {
725 Included(ref x) => Included(x),
726 Excluded(ref x) => Excluded(x),
727 Unbounded => Unbounded,
728 }
729 }
730
731 #[inline]
733 #[unstable(feature = "bound_as_ref", issue = "80996")]
734 pub const fn as_mut(&mut self) -> Bound<&mut T> {
735 match *self {
736 Included(ref mut x) => Included(x),
737 Excluded(ref mut x) => Excluded(x),
738 Unbounded => Unbounded,
739 }
740 }
741
742 #[inline]
764 #[stable(feature = "bound_map", since = "1.77.0")]
765 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U> {
766 match self {
767 Unbounded => Unbounded,
768 Included(x) => Included(f(x)),
769 Excluded(x) => Excluded(f(x)),
770 }
771 }
772}
773
774impl<T: Copy> Bound<&T> {
775 #[unstable(feature = "bound_copied", issue = "145966")]
789 #[must_use]
790 pub const fn copied(self) -> Bound<T> {
791 match self {
792 Bound::Unbounded => Bound::Unbounded,
793 Bound::Included(x) => Bound::Included(*x),
794 Bound::Excluded(x) => Bound::Excluded(*x),
795 }
796 }
797}
798
799impl<T: Clone> Bound<&T> {
800 #[must_use = "`self` will be dropped if the result is not used"]
815 #[stable(feature = "bound_cloned", since = "1.55.0")]
816 #[rustc_const_unstable(feature = "const_range", issue = "none")]
817 pub const fn cloned(self) -> Bound<T>
818 where
819 T: [const] Clone,
820 {
821 match self {
822 Bound::Unbounded => Bound::Unbounded,
823 Bound::Included(x) => Bound::Included(x.clone()),
824 Bound::Excluded(x) => Bound::Excluded(x.clone()),
825 }
826 }
827}
828
829#[stable(feature = "collections_range", since = "1.28.0")]
832#[rustc_diagnostic_item = "RangeBounds"]
833#[rustc_const_unstable(feature = "const_range", issue = "none")]
834pub const trait RangeBounds<T: ?Sized> {
835 #[stable(feature = "collections_range", since = "1.28.0")]
849 fn start_bound(&self) -> Bound<&T>;
850
851 #[stable(feature = "collections_range", since = "1.28.0")]
865 fn end_bound(&self) -> Bound<&T>;
866
867 #[inline]
881 #[stable(feature = "range_contains", since = "1.35.0")]
882 fn contains<U>(&self, item: &U) -> bool
883 where
884 T: [const] PartialOrd<U>,
885 U: ?Sized + [const] PartialOrd<T>,
886 {
887 (match self.start_bound() {
888 Included(start) => start <= item,
889 Excluded(start) => start < item,
890 Unbounded => true,
891 }) && (match self.end_bound() {
892 Included(end) => item <= end,
893 Excluded(end) => item < end,
894 Unbounded => true,
895 })
896 }
897
898 #[unstable(feature = "range_bounds_is_empty", issue = "137300")]
950 fn is_empty(&self) -> bool
951 where
952 T: [const] PartialOrd,
953 {
954 !match (self.start_bound(), self.end_bound()) {
955 (Unbounded, _) | (_, Unbounded) => true,
956 (Included(start), Excluded(end))
957 | (Excluded(start), Included(end))
958 | (Excluded(start), Excluded(end)) => start < end,
959 (Included(start), Included(end)) => start <= end,
960 }
961 }
962}
963
964#[unstable(feature = "range_into_bounds", issue = "136903")]
970#[rustc_const_unstable(feature = "const_range", issue = "none")]
971pub const trait IntoBounds<T>: [const] RangeBounds<T> {
972 fn into_bounds(self) -> (Bound<T>, Bound<T>);
986
987 fn intersect<R>(self, other: R) -> (Bound<T>, Bound<T>)
1015 where
1016 Self: Sized,
1017 T: [const] Ord + [const] Destruct,
1018 R: Sized + [const] IntoBounds<T>,
1019 {
1020 let (self_start, self_end) = IntoBounds::into_bounds(self);
1021 let (other_start, other_end) = IntoBounds::into_bounds(other);
1022
1023 let start = match (self_start, other_start) {
1024 (Included(a), Included(b)) => Included(Ord::max(a, b)),
1025 (Excluded(a), Excluded(b)) => Excluded(Ord::max(a, b)),
1026 (Unbounded, Unbounded) => Unbounded,
1027
1028 (x, Unbounded) | (Unbounded, x) => x,
1029
1030 (Included(i), Excluded(e)) | (Excluded(e), Included(i)) => {
1031 if i > e {
1032 Included(i)
1033 } else {
1034 Excluded(e)
1035 }
1036 }
1037 };
1038 let end = match (self_end, other_end) {
1039 (Included(a), Included(b)) => Included(Ord::min(a, b)),
1040 (Excluded(a), Excluded(b)) => Excluded(Ord::min(a, b)),
1041 (Unbounded, Unbounded) => Unbounded,
1042
1043 (x, Unbounded) | (Unbounded, x) => x,
1044
1045 (Included(i), Excluded(e)) | (Excluded(e), Included(i)) => {
1046 if i < e {
1047 Included(i)
1048 } else {
1049 Excluded(e)
1050 }
1051 }
1052 };
1053
1054 (start, end)
1055 }
1056}
1057
1058use self::Bound::{Excluded, Included, Unbounded};
1059
1060#[stable(feature = "collections_range", since = "1.28.0")]
1061#[rustc_const_unstable(feature = "const_range", issue = "none")]
1062const impl<T: ?Sized> RangeBounds<T> for RangeFull {
1063 fn start_bound(&self) -> Bound<&T> {
1064 Unbounded
1065 }
1066 fn end_bound(&self) -> Bound<&T> {
1067 Unbounded
1068 }
1069}
1070
1071#[unstable(feature = "range_into_bounds", issue = "136903")]
1072#[rustc_const_unstable(feature = "const_range", issue = "none")]
1073const impl<T> IntoBounds<T> for RangeFull {
1074 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1075 (Unbounded, Unbounded)
1076 }
1077}
1078
1079#[stable(feature = "collections_range", since = "1.28.0")]
1080#[rustc_const_unstable(feature = "const_range", issue = "none")]
1081const impl<T> RangeBounds<T> for RangeFrom<T> {
1082 fn start_bound(&self) -> Bound<&T> {
1083 Included(&self.start)
1084 }
1085 fn end_bound(&self) -> Bound<&T> {
1086 Unbounded
1087 }
1088}
1089
1090#[unstable(feature = "range_into_bounds", issue = "136903")]
1091#[rustc_const_unstable(feature = "const_range", issue = "none")]
1092const impl<T> IntoBounds<T> for RangeFrom<T> {
1093 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1094 (Included(self.start), Unbounded)
1095 }
1096}
1097
1098#[stable(feature = "collections_range", since = "1.28.0")]
1099#[rustc_const_unstable(feature = "const_range", issue = "none")]
1100const impl<T> RangeBounds<T> for RangeTo<T> {
1101 fn start_bound(&self) -> Bound<&T> {
1102 Unbounded
1103 }
1104 fn end_bound(&self) -> Bound<&T> {
1105 Excluded(&self.end)
1106 }
1107}
1108
1109#[unstable(feature = "range_into_bounds", issue = "136903")]
1110#[rustc_const_unstable(feature = "const_range", issue = "none")]
1111const impl<T> IntoBounds<T> for RangeTo<T> {
1112 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1113 (Unbounded, Excluded(self.end))
1114 }
1115}
1116
1117#[stable(feature = "collections_range", since = "1.28.0")]
1118#[rustc_const_unstable(feature = "const_range", issue = "none")]
1119const impl<T> RangeBounds<T> for Range<T> {
1120 fn start_bound(&self) -> Bound<&T> {
1121 Included(&self.start)
1122 }
1123 fn end_bound(&self) -> Bound<&T> {
1124 Excluded(&self.end)
1125 }
1126}
1127
1128#[unstable(feature = "range_into_bounds", issue = "136903")]
1129#[rustc_const_unstable(feature = "const_range", issue = "none")]
1130const impl<T> IntoBounds<T> for Range<T> {
1131 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1132 (Included(self.start), Excluded(self.end))
1133 }
1134}
1135
1136#[stable(feature = "collections_range", since = "1.28.0")]
1137#[rustc_const_unstable(feature = "const_range", issue = "none")]
1138const impl<T> RangeBounds<T> for RangeInclusive<T> {
1139 fn start_bound(&self) -> Bound<&T> {
1140 Included(&self.start)
1141 }
1142 fn end_bound(&self) -> Bound<&T> {
1143 if self.exhausted {
1144 Excluded(&self.start)
1149 } else {
1150 Included(&self.end)
1151 }
1152 }
1153}
1154
1155#[unstable(feature = "range_into_bounds", issue = "136903")]
1156#[rustc_const_unstable(feature = "const_range", issue = "none")]
1157const impl<T> IntoBounds<T> for RangeInclusive<T> {
1158 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1159 if !!self.exhausted {
{
crate::panicking::panic_fmt(format_args!("attempted to convert from an exhausted `RangeInclusive` (unspecified behavior)"));
}
};assert!(
1160 !self.exhausted,
1161 "attempted to convert from an exhausted `RangeInclusive` (unspecified behavior)"
1162 );
1163
1164 (Included(self.start), Included(self.end))
1165 }
1166}
1167
1168#[stable(feature = "collections_range", since = "1.28.0")]
1169#[rustc_const_unstable(feature = "const_range", issue = "none")]
1170const impl<T> RangeBounds<T> for RangeToInclusive<T> {
1171 fn start_bound(&self) -> Bound<&T> {
1172 Unbounded
1173 }
1174 fn end_bound(&self) -> Bound<&T> {
1175 Included(&self.end)
1176 }
1177}
1178
1179#[unstable(feature = "range_into_bounds", issue = "136903")]
1180#[rustc_const_unstable(feature = "const_range", issue = "none")]
1181const impl<T> IntoBounds<T> for RangeToInclusive<T> {
1182 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1183 (Unbounded, Included(self.end))
1184 }
1185}
1186
1187#[stable(feature = "collections_range", since = "1.28.0")]
1188#[rustc_const_unstable(feature = "const_range", issue = "none")]
1189const impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
1190 fn start_bound(&self) -> Bound<&T> {
1191 match *self {
1192 (Included(ref start), _) => Included(start),
1193 (Excluded(ref start), _) => Excluded(start),
1194 (Unbounded, _) => Unbounded,
1195 }
1196 }
1197
1198 fn end_bound(&self) -> Bound<&T> {
1199 match *self {
1200 (_, Included(ref end)) => Included(end),
1201 (_, Excluded(ref end)) => Excluded(end),
1202 (_, Unbounded) => Unbounded,
1203 }
1204 }
1205}
1206
1207#[unstable(feature = "range_into_bounds", issue = "136903")]
1208#[rustc_const_unstable(feature = "const_range", issue = "none")]
1209const impl<T> IntoBounds<T> for (Bound<T>, Bound<T>) {
1210 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1211 self
1212 }
1213}
1214
1215#[stable(feature = "collections_range", since = "1.28.0")]
1216#[rustc_const_unstable(feature = "const_range", issue = "none")]
1217const impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
1218 fn start_bound(&self) -> Bound<&T> {
1219 self.0
1220 }
1221
1222 fn end_bound(&self) -> Bound<&T> {
1223 self.1
1224 }
1225}
1226
1227#[stable(feature = "collections_range", since = "1.28.0")]
1234#[rustc_const_unstable(feature = "const_range", issue = "none")]
1235const impl<T> RangeBounds<T> for RangeFrom<&T> {
1236 fn start_bound(&self) -> Bound<&T> {
1237 Included(self.start)
1238 }
1239 fn end_bound(&self) -> Bound<&T> {
1240 Unbounded
1241 }
1242}
1243
1244#[stable(feature = "collections_range", since = "1.28.0")]
1251#[rustc_const_unstable(feature = "const_range", issue = "none")]
1252const impl<T> RangeBounds<T> for RangeTo<&T> {
1253 fn start_bound(&self) -> Bound<&T> {
1254 Unbounded
1255 }
1256 fn end_bound(&self) -> Bound<&T> {
1257 Excluded(self.end)
1258 }
1259}
1260
1261#[stable(feature = "collections_range", since = "1.28.0")]
1268#[rustc_const_unstable(feature = "const_range", issue = "none")]
1269const impl<T> RangeBounds<T> for Range<&T> {
1270 fn start_bound(&self) -> Bound<&T> {
1271 Included(self.start)
1272 }
1273 fn end_bound(&self) -> Bound<&T> {
1274 Excluded(self.end)
1275 }
1276}
1277
1278#[stable(feature = "collections_range", since = "1.28.0")]
1285#[rustc_const_unstable(feature = "const_range", issue = "none")]
1286const impl<T> RangeBounds<T> for RangeInclusive<&T> {
1287 fn start_bound(&self) -> Bound<&T> {
1288 Included(self.start)
1289 }
1290 fn end_bound(&self) -> Bound<&T> {
1291 Included(self.end)
1292 }
1293}
1294
1295#[stable(feature = "collections_range", since = "1.28.0")]
1302#[rustc_const_unstable(feature = "const_range", issue = "none")]
1303const impl<T> RangeBounds<T> for RangeToInclusive<&T> {
1304 fn start_bound(&self) -> Bound<&T> {
1305 Unbounded
1306 }
1307 fn end_bound(&self) -> Bound<&T> {
1308 Included(self.end)
1309 }
1310}
1311
1312#[unstable(feature = "one_sided_range", issue = "69780")]
1315#[allow(missing_debug_implementations)]
1316pub enum OneSidedRangeBound {
1317 StartInclusive,
1319 End,
1321 EndInclusive,
1323}
1324
1325#[unstable(feature = "one_sided_range", issue = "69780")]
1332#[rustc_const_unstable(feature = "const_range", issue = "none")]
1333pub const trait OneSidedRange<T>: RangeBounds<T> {
1334 fn bound(self) -> (OneSidedRangeBound, T);
1337}
1338
1339#[unstable(feature = "one_sided_range", issue = "69780")]
1340#[rustc_const_unstable(feature = "const_range", issue = "none")]
1341const impl<T> OneSidedRange<T> for RangeTo<T>
1342where
1343 Self: RangeBounds<T>,
1344{
1345 fn bound(self) -> (OneSidedRangeBound, T) {
1346 (OneSidedRangeBound::End, self.end)
1347 }
1348}
1349
1350#[unstable(feature = "one_sided_range", issue = "69780")]
1351#[rustc_const_unstable(feature = "const_range", issue = "none")]
1352const impl<T> OneSidedRange<T> for RangeFrom<T>
1353where
1354 Self: RangeBounds<T>,
1355{
1356 fn bound(self) -> (OneSidedRangeBound, T) {
1357 (OneSidedRangeBound::StartInclusive, self.start)
1358 }
1359}
1360
1361#[unstable(feature = "one_sided_range", issue = "69780")]
1362#[rustc_const_unstable(feature = "const_range", issue = "none")]
1363const impl<T> OneSidedRange<T> for RangeToInclusive<T>
1364where
1365 Self: RangeBounds<T>,
1366{
1367 fn bound(self) -> (OneSidedRangeBound, T) {
1368 (OneSidedRangeBound::EndInclusive, self.end)
1369 }
1370}