cfg_if! {
if #[cfg(feature = "std")] {
use std::ops;
} else {
use core::ops;
}
}
use self::ops::{Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo};
mod private {
pub trait Sealed {}
impl Sealed for str {}
impl<T> Sealed for [T] {}
}
pub trait IndexRange<Idx>
: Index<Range<Idx>, Output = <Self as Index<RangeFull>>::Output>
+ Index<RangeTo<Idx>, Output = <Self as Index<RangeFull>>::Output>
+ Index<RangeFrom<Idx>, Output = <Self as Index<RangeFull>>::Output>
+ Index<RangeFull>
+ private::Sealed {
}
impl<T: ?Sized, Idx> IndexRange<Idx> for T
where
T: Index<
Range<Idx>,
Output = <T as Index<RangeFull>>::Output,
>,
T: Index<
RangeTo<Idx>,
Output = <T as Index<RangeFull>>::Output,
>,
T: Index<
RangeFrom<Idx>,
Output = <T as Index<RangeFull>>::Output,
>,
T: Index<RangeFull>,
T: private::Sealed,
{
}
pub trait IndexRangeMut<Idx>
: IndexMut<Range<Idx>>
+ IndexMut<RangeTo<Idx>>
+ IndexMut<RangeFrom<Idx>>
+ IndexMut<RangeFull>
+ IndexRange<Idx> {
}
impl<T: ?Sized, Idx> IndexRangeMut<Idx> for T
where
T: IndexMut<Range<Idx>>,
T: IndexMut<RangeTo<Idx>>,
T: IndexMut<RangeFrom<Idx>>,
T: IndexMut<RangeFull>,
T: IndexRange<Idx>,
{
}
pub trait SplitAt<Idx>: IndexRange<Idx> {
fn split_at(
&self,
index: Idx,
) -> (&<Self as Index<RangeFull>>::Output, &<Self as Index<RangeFull>>::Output);
}
pub trait SplitAtMut<Idx>: IndexRangeMut<Idx> + SplitAt<Idx> {
fn split_at_mut(
&mut self,
index: Idx,
) -> (&mut <Self as Index<RangeFull>>::Output, &mut <Self as Index<RangeFull>>::Output);
}