1use crate::fmt;
2use crate::hash::Hash;
3#[lang = "RangeFull"]
39#[doc(alias = "..")]
40#[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)]
41#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[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 = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::clone::Clone for RangeFull {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::default::Default for RangeFull {
#[inline]
fn default() -> Self { RangeFull {} }
}Default, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::Eq for RangeFull { }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 = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl crate::cmp::PartialEq for RangeFull {
#[inline]
fn eq(&self, other: &Self) -> bool { true }
}PartialEq)]
42#[stable(feature = "rust1", since = "1.0.0")]
43pub struct RangeFull;
44
45#[stable(feature = "rust1", since = "1.0.0")]
46impl fmt::Debug for RangeFull {
47 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
48 fmt.write_fmt(format_args!(".."))write!(fmt, "..")
49 }
50}
51
52#[lang = "Range"]
81#[doc(alias = "..")]
82#[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)]
83#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::clone::Clone> crate::clone::Clone for
Range<Idx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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 = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::default::Default> crate::default::Default for
Range<Idx> {
#[inline]
fn default() -> Self {
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 = "143874")]#[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: &Self) -> bool {
self.start == other.start && self.end == other.end
}
}PartialEq)] #[stable(feature = "rust1", since = "1.0.0")]
85pub struct Range<Idx> {
86 #[stable(feature = "rust1", since = "1.0.0")]
88 pub start: Idx,
89 #[stable(feature = "rust1", since = "1.0.0")]
91 pub end: Idx,
92}
93
94#[stable(feature = "rust1", since = "1.0.0")]
95impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
96 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
97 self.start.fmt(fmt)?;
98 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
99 self.end.fmt(fmt)?;
100 Ok(())
101 }
102}
103
104impl<Idx: PartialOrd<Idx>> Range<Idx> {
105 #[inline]
124 #[stable(feature = "range_contains", since = "1.35.0")]
125 #[rustc_const_unstable(feature = "const_range", issue = "none")]
126 pub const fn contains<U>(&self, item: &U) -> bool
127 where
128 Idx: [const] PartialOrd<U>,
129 U: ?Sized + [const] PartialOrd<Idx>,
130 {
131 <Self as RangeBounds<Idx>>::contains(self, item)
132 }
133
134 #[inline]
152 #[stable(feature = "range_is_empty", since = "1.47.0")]
153 #[rustc_const_unstable(feature = "const_range", issue = "none")]
154 #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")]
155 pub const fn is_empty(&self) -> bool
156 where
157 Idx: [const] PartialOrd<Idx>,
158 {
159 !(self.start < self.end)
160 }
161}
162
163#[lang = "RangeFrom"]
197#[doc(alias = "..")]
198#[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)]
199#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::clone::Clone> crate::clone::Clone for
RangeFrom<Idx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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 = "143874")]#[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: &Self) -> bool { self.start == other.start }
}PartialEq)] #[stable(feature = "rust1", since = "1.0.0")]
201pub struct RangeFrom<Idx> {
202 #[stable(feature = "rust1", since = "1.0.0")]
204 pub start: Idx,
205}
206
207#[stable(feature = "rust1", since = "1.0.0")]
208impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
209 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
210 self.start.fmt(fmt)?;
211 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
212 Ok(())
213 }
214}
215
216impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
217 #[inline]
231 #[stable(feature = "range_contains", since = "1.35.0")]
232 #[rustc_const_unstable(feature = "const_range", issue = "none")]
233 pub const fn contains<U>(&self, item: &U) -> bool
234 where
235 Idx: [const] PartialOrd<U>,
236 U: ?Sized + [const] PartialOrd<Idx>,
237 {
238 <Self as RangeBounds<Idx>>::contains(self, item)
239 }
240}
241
242#[lang = "RangeTo"]
281#[doc(alias = "..")]
282#[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)]
283#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "rust1", since = "1.0.0")]
const impl<Idx: [const] crate::clone::Clone> crate::clone::Clone for
RangeTo<Idx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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 = "143874")]#[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: &Self) -> bool { self.end == other.end }
}PartialEq)]
284#[stable(feature = "rust1", since = "1.0.0")]
285pub struct RangeTo<Idx> {
286 #[stable(feature = "rust1", since = "1.0.0")]
288 pub end: Idx,
289}
290
291#[stable(feature = "rust1", since = "1.0.0")]
292impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
293 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
294 fmt.write_fmt(format_args!(".."))write!(fmt, "..")?;
295 self.end.fmt(fmt)?;
296 Ok(())
297 }
298}
299
300impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
301 #[inline]
315 #[stable(feature = "range_contains", since = "1.35.0")]
316 #[rustc_const_unstable(feature = "const_range", issue = "none")]
317 pub const fn contains<U>(&self, item: &U) -> bool
318 where
319 Idx: [const] PartialOrd<U>,
320 U: ?Sized + [const] PartialOrd<Idx>,
321 {
322 <Self as RangeBounds<Idx>>::contains(self, item)
323 }
324}
325
326#[lang = "RangeInclusive"]
357#[doc(alias = "..=")]
358#[derive(#[automatically_derived]#[stable(feature = "inclusive_range", since =
"1.26.0")]
impl<Idx: crate::clone::Clone> crate::clone::Clone for RangeInclusive<Idx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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)]
359#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[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 = "143874")]#[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: &Self) -> bool {
self.exhausted == other.exhausted && self.start == other.start &&
self.end == other.end
}
}PartialEq)] #[stable(feature = "inclusive_range", since = "1.26.0")]
361pub struct RangeInclusive<Idx> {
362 pub(crate) start: Idx,
368 pub(crate) end: Idx,
369
370 pub(crate) exhausted: bool,
382}
383
384impl<Idx> RangeInclusive<Idx> {
385 #[lang = "range_inclusive_new"]
395 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
396 #[inline]
397 #[rustc_promotable]
398 #[rustc_const_stable(feature = "const_range_new", since = "1.32.0")]
399 pub const fn new(start: Idx, end: Idx) -> Self {
400 Self { start, end, exhausted: false }
401 }
402
403 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
422 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
423 #[inline]
424 pub const fn start(&self) -> &Idx {
425 &self.start
426 }
427
428 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
447 #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")]
448 #[inline]
449 pub const fn end(&self) -> &Idx {
450 &self.end
451 }
452
453 #[stable(feature = "inclusive_range_methods", since = "1.27.0")]
464 #[inline]
465 #[rustc_const_unstable(feature = "const_range_bounds", issue = "108082")]
466 pub const fn into_inner(self) -> (Idx, Idx) {
467 (self.start, self.end)
468 }
469}
470
471impl RangeInclusive<usize> {
472 #[inline]
475 pub(crate) const fn into_slice_range(self) -> Range<usize> {
476 let exclusive_end = self.end + 1;
487 let start = if self.exhausted { exclusive_end } else { self.start };
488 start..exclusive_end
489 }
490}
491
492#[stable(feature = "inclusive_range", since = "1.26.0")]
493impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
494 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
495 self.start.fmt(fmt)?;
496 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
497 self.end.fmt(fmt)?;
498 if self.exhausted {
499 fmt.write_fmt(format_args!(" (exhausted)"))write!(fmt, " (exhausted)")?;
500 }
501 Ok(())
502 }
503}
504
505impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
506 #[inline]
536 #[stable(feature = "range_contains", since = "1.35.0")]
537 #[rustc_const_unstable(feature = "const_range", issue = "none")]
538 pub const fn contains<U>(&self, item: &U) -> bool
539 where
540 Idx: [const] PartialOrd<U>,
541 U: ?Sized + [const] PartialOrd<Idx>,
542 {
543 <Self as RangeBounds<Idx>>::contains(self, item)
544 }
545
546 #[stable(feature = "range_is_empty", since = "1.47.0")]
573 #[inline]
574 #[rustc_const_unstable(feature = "const_range", issue = "none")]
575 #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")]
576 pub const fn is_empty(&self) -> bool
577 where
578 Idx: [const] PartialOrd,
579 {
580 self.exhausted || !(self.start <= self.end)
581 }
582}
583
584#[lang = "RangeToInclusive"]
623#[doc(alias = "..=")]
624#[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)]
625#[derive(#[automatically_derived]#[stable(feature = "inclusive_range", since =
"1.26.0")]
impl<Idx: crate::clone::Clone> crate::clone::Clone for RangeToInclusive<Idx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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: &Self) -> 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)]
626#[stable(feature = "inclusive_range", since = "1.26.0")]
627pub struct RangeToInclusive<Idx> {
628 #[stable(feature = "inclusive_range", since = "1.26.0")]
630 pub end: Idx,
631}
632
633#[stable(feature = "inclusive_range", since = "1.26.0")]
634impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
635 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
636 fmt.write_fmt(format_args!("..="))write!(fmt, "..=")?;
637 self.end.fmt(fmt)?;
638 Ok(())
639 }
640}
641
642impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
643 #[inline]
657 #[stable(feature = "range_contains", since = "1.35.0")]
658 #[rustc_const_unstable(feature = "const_range", issue = "none")]
659 pub const fn contains<U>(&self, item: &U) -> bool
660 where
661 Idx: [const] PartialOrd<U>,
662 U: ?Sized + [const] PartialOrd<Idx>,
663 {
664 <Self as RangeBounds<Idx>>::contains(self, item)
665 }
666}
667
668#[stable(feature = "collections_bound", since = "1.17.0")]
707#[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]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
match self {
Self::Included(__self_0) =>
crate::fmt::Formatter::debug_struct_field1_finish(f,
"Included", &__self_0),
Self::Excluded(__self_0) =>
crate::fmt::Formatter::debug_struct_field1_finish(f,
"Excluded", &__self_0),
Self::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) {
crate::hash::Hash::hash(&crate::intrinsics::discriminant_value(self),
state);
match self {
Self::Included(__self_0) =>
crate::hash::Hash::hash(__self_0, state),
Self::Excluded(__self_0) =>
crate::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
708#[derive_const(#[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[stable(feature
= "collections_bound", since = "1.17.0")]
const impl<T: [const] crate::clone::Clone> crate::clone::Clone for Bound<T> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Included(__self_0) =>
Bound::Included(crate::clone::Clone::clone(__self_0)),
Self::Excluded(__self_0) =>
Bound::Excluded(crate::clone::Clone::clone(__self_0)),
Self::Unbounded => Bound::Unbounded,
}
}
}Clone, #[automatically_derived]#[rustc_const_unstable(feature = "derive_const", issue = "143874")]#[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 = "143874")]#[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: &Self) -> bool {
crate::intrinsics::discriminant_value(self) ==
crate::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Included(__self_0), Self::Included(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Excluded(__self_0), Self::Excluded(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
709pub enum Bound<T> {
710 #[stable(feature = "collections_bound", since = "1.17.0")]
712 Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
713 #[stable(feature = "collections_bound", since = "1.17.0")]
715 Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
716 #[stable(feature = "collections_bound", since = "1.17.0")]
718 Unbounded,
719}
720
721impl<T> Bound<T> {
722 #[inline]
724 #[stable(feature = "bound_as_ref_shared", since = "1.65.0")]
725 #[rustc_const_unstable(feature = "const_range", issue = "none")]
726 pub const fn as_ref(&self) -> Bound<&T> {
727 match *self {
728 Included(ref x) => Included(x),
729 Excluded(ref x) => Excluded(x),
730 Unbounded => Unbounded,
731 }
732 }
733
734 #[inline]
736 #[unstable(feature = "bound_as_ref", issue = "80996")]
737 pub const fn as_mut(&mut self) -> Bound<&mut T> {
738 match *self {
739 Included(ref mut x) => Included(x),
740 Excluded(ref mut x) => Excluded(x),
741 Unbounded => Unbounded,
742 }
743 }
744
745 #[inline]
767 #[stable(feature = "bound_map", since = "1.77.0")]
768 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Bound<U> {
769 match self {
770 Unbounded => Unbounded,
771 Included(x) => Included(f(x)),
772 Excluded(x) => Excluded(f(x)),
773 }
774 }
775}
776
777impl<T: Copy> Bound<&T> {
778 #[unstable(feature = "bound_copied", issue = "145966")]
792 #[must_use]
793 pub const fn copied(self) -> Bound<T> {
794 match self {
795 Bound::Unbounded => Bound::Unbounded,
796 Bound::Included(x) => Bound::Included(*x),
797 Bound::Excluded(x) => Bound::Excluded(*x),
798 }
799 }
800}
801
802impl<T: Clone> Bound<&T> {
803 #[must_use = "`self` will be dropped if the result is not used"]
818 #[stable(feature = "bound_cloned", since = "1.55.0")]
819 #[rustc_const_unstable(feature = "const_range", issue = "none")]
820 pub const fn cloned(self) -> Bound<T>
821 where
822 T: [const] Clone,
823 {
824 match self {
825 Bound::Unbounded => Bound::Unbounded,
826 Bound::Included(x) => Bound::Included(x.clone()),
827 Bound::Excluded(x) => Bound::Excluded(x.clone()),
828 }
829 }
830}
831
832#[stable(feature = "collections_range", since = "1.28.0")]
835#[rustc_diagnostic_item = "RangeBounds"]
836#[rustc_const_unstable(feature = "const_range", issue = "none")]
837pub const trait RangeBounds<T: ?Sized> {
838 #[stable(feature = "collections_range", since = "1.28.0")]
852 fn start_bound(&self) -> Bound<&T>;
853
854 #[stable(feature = "collections_range", since = "1.28.0")]
868 fn end_bound(&self) -> Bound<&T>;
869
870 #[inline]
884 #[stable(feature = "range_contains", since = "1.35.0")]
885 fn contains<U>(&self, item: &U) -> bool
886 where
887 T: [const] PartialOrd<U>,
888 U: ?Sized + [const] PartialOrd<T>,
889 {
890 (match self.start_bound() {
891 Included(start) => start <= item,
892 Excluded(start) => start < item,
893 Unbounded => true,
894 }) && (match self.end_bound() {
895 Included(end) => item <= end,
896 Excluded(end) => item < end,
897 Unbounded => true,
898 })
899 }
900
901 #[unstable(feature = "range_bounds_is_empty", issue = "137300")]
953 fn is_empty(&self) -> bool
954 where
955 T: [const] PartialOrd,
956 {
957 !match (self.start_bound(), self.end_bound()) {
958 (Unbounded, _) | (_, Unbounded) => true,
959 (Included(start), Excluded(end))
960 | (Excluded(start), Included(end))
961 | (Excluded(start), Excluded(end)) => start < end,
962 (Included(start), Included(end)) => start <= end,
963 }
964 }
965}
966
967#[unstable(feature = "range_into_bounds", issue = "136903")]
973#[rustc_const_unstable(feature = "const_range", issue = "none")]
974pub const trait IntoBounds<T>: [const] RangeBounds<T> {
975 fn into_bounds(self) -> (Bound<T>, Bound<T>);
989}
990
991use self::Bound::{Excluded, Included, Unbounded};
992
993#[stable(feature = "collections_range", since = "1.28.0")]
994#[rustc_const_unstable(feature = "const_range", issue = "none")]
995const impl<T: ?Sized> RangeBounds<T> for RangeFull {
996 fn start_bound(&self) -> Bound<&T> {
997 Unbounded
998 }
999 fn end_bound(&self) -> Bound<&T> {
1000 Unbounded
1001 }
1002}
1003
1004#[unstable(feature = "range_into_bounds", issue = "136903")]
1005#[rustc_const_unstable(feature = "const_range", issue = "none")]
1006const impl<T> IntoBounds<T> for RangeFull {
1007 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1008 (Unbounded, Unbounded)
1009 }
1010}
1011
1012#[stable(feature = "collections_range", since = "1.28.0")]
1013#[rustc_const_unstable(feature = "const_range", issue = "none")]
1014const impl<T> RangeBounds<T> for RangeFrom<T> {
1015 fn start_bound(&self) -> Bound<&T> {
1016 Included(&self.start)
1017 }
1018 fn end_bound(&self) -> Bound<&T> {
1019 Unbounded
1020 }
1021}
1022
1023#[unstable(feature = "range_into_bounds", issue = "136903")]
1024#[rustc_const_unstable(feature = "const_range", issue = "none")]
1025const impl<T> IntoBounds<T> for RangeFrom<T> {
1026 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1027 (Included(self.start), Unbounded)
1028 }
1029}
1030
1031#[stable(feature = "collections_range", since = "1.28.0")]
1032#[rustc_const_unstable(feature = "const_range", issue = "none")]
1033const impl<T> RangeBounds<T> for RangeTo<T> {
1034 fn start_bound(&self) -> Bound<&T> {
1035 Unbounded
1036 }
1037 fn end_bound(&self) -> Bound<&T> {
1038 Excluded(&self.end)
1039 }
1040}
1041
1042#[unstable(feature = "range_into_bounds", issue = "136903")]
1043#[rustc_const_unstable(feature = "const_range", issue = "none")]
1044const impl<T> IntoBounds<T> for RangeTo<T> {
1045 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1046 (Unbounded, Excluded(self.end))
1047 }
1048}
1049
1050#[stable(feature = "collections_range", since = "1.28.0")]
1051#[rustc_const_unstable(feature = "const_range", issue = "none")]
1052const impl<T> RangeBounds<T> for Range<T> {
1053 fn start_bound(&self) -> Bound<&T> {
1054 Included(&self.start)
1055 }
1056 fn end_bound(&self) -> Bound<&T> {
1057 Excluded(&self.end)
1058 }
1059}
1060
1061#[unstable(feature = "range_into_bounds", issue = "136903")]
1062#[rustc_const_unstable(feature = "const_range", issue = "none")]
1063const impl<T> IntoBounds<T> for Range<T> {
1064 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1065 (Included(self.start), Excluded(self.end))
1066 }
1067}
1068
1069#[stable(feature = "collections_range", since = "1.28.0")]
1070#[rustc_const_unstable(feature = "const_range", issue = "none")]
1071const impl<T> RangeBounds<T> for RangeInclusive<T> {
1072 fn start_bound(&self) -> Bound<&T> {
1073 Included(&self.start)
1074 }
1075 fn end_bound(&self) -> Bound<&T> {
1076 if self.exhausted {
1077 Excluded(&self.start)
1082 } else {
1083 Included(&self.end)
1084 }
1085 }
1086}
1087
1088#[unstable(feature = "range_into_bounds", issue = "136903")]
1089#[rustc_const_unstable(feature = "const_range", issue = "none")]
1090const impl<T> IntoBounds<T> for RangeInclusive<T> {
1091 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1092 if !!self.exhausted {
{
crate::panicking::panic_fmt(format_args!("attempted to convert from an exhausted `RangeInclusive` (unspecified behavior)"));
}
};assert!(
1093 !self.exhausted,
1094 "attempted to convert from an exhausted `RangeInclusive` (unspecified behavior)"
1095 );
1096
1097 (Included(self.start), Included(self.end))
1098 }
1099}
1100
1101#[stable(feature = "collections_range", since = "1.28.0")]
1102#[rustc_const_unstable(feature = "const_range", issue = "none")]
1103const impl<T> RangeBounds<T> for RangeToInclusive<T> {
1104 fn start_bound(&self) -> Bound<&T> {
1105 Unbounded
1106 }
1107 fn end_bound(&self) -> Bound<&T> {
1108 Included(&self.end)
1109 }
1110}
1111
1112#[unstable(feature = "range_into_bounds", issue = "136903")]
1113#[rustc_const_unstable(feature = "const_range", issue = "none")]
1114const impl<T> IntoBounds<T> for RangeToInclusive<T> {
1115 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1116 (Unbounded, Included(self.end))
1117 }
1118}
1119
1120#[stable(feature = "collections_range", since = "1.28.0")]
1121#[rustc_const_unstable(feature = "const_range", issue = "none")]
1122const impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
1123 fn start_bound(&self) -> Bound<&T> {
1124 match *self {
1125 (Included(ref start), _) => Included(start),
1126 (Excluded(ref start), _) => Excluded(start),
1127 (Unbounded, _) => Unbounded,
1128 }
1129 }
1130
1131 fn end_bound(&self) -> Bound<&T> {
1132 match *self {
1133 (_, Included(ref end)) => Included(end),
1134 (_, Excluded(ref end)) => Excluded(end),
1135 (_, Unbounded) => Unbounded,
1136 }
1137 }
1138}
1139
1140#[unstable(feature = "range_into_bounds", issue = "136903")]
1141#[rustc_const_unstable(feature = "const_range", issue = "none")]
1142const impl<T> IntoBounds<T> for (Bound<T>, Bound<T>) {
1143 fn into_bounds(self) -> (Bound<T>, Bound<T>) {
1144 self
1145 }
1146}
1147
1148#[stable(feature = "collections_range", since = "1.28.0")]
1149#[rustc_const_unstable(feature = "const_range", issue = "none")]
1150const impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
1151 fn start_bound(&self) -> Bound<&T> {
1152 self.0
1153 }
1154
1155 fn end_bound(&self) -> Bound<&T> {
1156 self.1
1157 }
1158}
1159
1160#[stable(feature = "collections_range", since = "1.28.0")]
1167#[rustc_const_unstable(feature = "const_range", issue = "none")]
1168const impl<T> RangeBounds<T> for RangeFrom<&T> {
1169 fn start_bound(&self) -> Bound<&T> {
1170 Included(self.start)
1171 }
1172 fn end_bound(&self) -> Bound<&T> {
1173 Unbounded
1174 }
1175}
1176
1177#[stable(feature = "collections_range", since = "1.28.0")]
1184#[rustc_const_unstable(feature = "const_range", issue = "none")]
1185const impl<T> RangeBounds<T> for RangeTo<&T> {
1186 fn start_bound(&self) -> Bound<&T> {
1187 Unbounded
1188 }
1189 fn end_bound(&self) -> Bound<&T> {
1190 Excluded(self.end)
1191 }
1192}
1193
1194#[stable(feature = "collections_range", since = "1.28.0")]
1201#[rustc_const_unstable(feature = "const_range", issue = "none")]
1202const impl<T> RangeBounds<T> for Range<&T> {
1203 fn start_bound(&self) -> Bound<&T> {
1204 Included(self.start)
1205 }
1206 fn end_bound(&self) -> Bound<&T> {
1207 Excluded(self.end)
1208 }
1209}
1210
1211#[stable(feature = "collections_range", since = "1.28.0")]
1218#[rustc_const_unstable(feature = "const_range", issue = "none")]
1219const impl<T> RangeBounds<T> for RangeInclusive<&T> {
1220 fn start_bound(&self) -> Bound<&T> {
1221 Included(self.start)
1222 }
1223 fn end_bound(&self) -> Bound<&T> {
1224 Included(self.end)
1225 }
1226}
1227
1228#[stable(feature = "collections_range", since = "1.28.0")]
1235#[rustc_const_unstable(feature = "const_range", issue = "none")]
1236const impl<T> RangeBounds<T> for RangeToInclusive<&T> {
1237 fn start_bound(&self) -> Bound<&T> {
1238 Unbounded
1239 }
1240 fn end_bound(&self) -> Bound<&T> {
1241 Included(self.end)
1242 }
1243}
1244
1245#[unstable(feature = "one_sided_range", issue = "69780")]
1248#[allow(missing_debug_implementations)]
1249pub enum OneSidedRangeBound {
1250 StartInclusive,
1252 End,
1254 EndInclusive,
1256}
1257
1258#[unstable(feature = "one_sided_range", issue = "69780")]
1265#[rustc_const_unstable(feature = "const_range", issue = "none")]
1266pub const trait OneSidedRange<T>: RangeBounds<T> {
1267 fn bound(self) -> (OneSidedRangeBound, T);
1270}
1271
1272#[unstable(feature = "one_sided_range", issue = "69780")]
1273#[rustc_const_unstable(feature = "const_range", issue = "none")]
1274const impl<T> OneSidedRange<T> for RangeTo<T>
1275where
1276 Self: RangeBounds<T>,
1277{
1278 fn bound(self) -> (OneSidedRangeBound, T) {
1279 (OneSidedRangeBound::End, self.end)
1280 }
1281}
1282
1283#[unstable(feature = "one_sided_range", issue = "69780")]
1284#[rustc_const_unstable(feature = "const_range", issue = "none")]
1285const impl<T> OneSidedRange<T> for RangeFrom<T>
1286where
1287 Self: RangeBounds<T>,
1288{
1289 fn bound(self) -> (OneSidedRangeBound, T) {
1290 (OneSidedRangeBound::StartInclusive, self.start)
1291 }
1292}
1293
1294#[unstable(feature = "one_sided_range", issue = "69780")]
1295#[rustc_const_unstable(feature = "const_range", issue = "none")]
1296const impl<T> OneSidedRange<T> for RangeToInclusive<T>
1297where
1298 Self: RangeBounds<T>,
1299{
1300 fn bound(self) -> (OneSidedRangeBound, T) {
1301 (OneSidedRangeBound::EndInclusive, self.end)
1302 }
1303}