use std::ops::{Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo};
#[cfg(feature = "nightly")]
use std::ops::{RangeInclusive, RangeToInclusive};
pub trait Len {
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
pub trait LenZero: Len {
fn clear(&mut self);
}
pub trait LenMut: Default + LenZero {
fn truncate(&mut self, len: usize);
}
pub trait Capacity {
fn capacity(&self) -> usize;
}
pub trait DefaultCapacity: Capacity + Default {
fn default_capacity(capacity: usize) -> Self;
}
pub trait CapacityMut: Len + DefaultCapacity {
fn reserve(&mut self, additional: usize);
fn reserve_exact(&mut self, additional: usize);
fn shrink_to_fit(&mut self);
}
#[cfg(feature = "nightly")]
pub trait IndexRanges: Index<Range<usize>, Output = Self>
+ Index<RangeTo<usize>, Output = Self>
+ Index<RangeFrom<usize>, Output = Self>
+ Index<RangeInclusive<usize>, Output = Self>
+ Index<RangeToInclusive<usize>, Output = Self>
+ Index<RangeFull, Output = Self> {}
#[cfg(feature = "nightly")]
impl<T: ?Sized> IndexRanges for T
where T: Index<Range<usize>, Output = Self>
+ Index<RangeTo<usize>, Output = Self>
+ Index<RangeFrom<usize>, Output = Self>
+ Index<RangeInclusive<usize>, Output = Self>
+ Index<RangeToInclusive<usize>, Output = Self>
+ Index<RangeFull, Output = Self>
{}
#[cfg(not(feature = "nightly"))]
pub trait IndexRanges: Index<Range<usize>, Output = Self>
+ Index<RangeTo<usize>, Output = Self>
+ Index<RangeFrom<usize>, Output = Self>
+ Index<RangeFull, Output = Self> {}
#[cfg(not(feature = "nightly"))]
impl<T: ?Sized> IndexRanges for T
where T: Index<Range<usize>, Output = Self>
+ Index<RangeTo<usize>, Output = Self>
+ Index<RangeFrom<usize>, Output = Self>
+ Index<RangeFull, Output = Self>
{}
#[cfg(feature = "nightly")]
pub trait IndexRangesMut: IndexMut<Range<usize>, Output = Self>
+ IndexMut<RangeTo<usize>, Output = Self>
+ IndexMut<RangeFrom<usize>, Output = Self>
+ IndexMut<RangeInclusive<usize>, Output = Self>
+ IndexMut<RangeToInclusive<usize>, Output = Self>
+ IndexMut<RangeFull, Output = Self> {}
#[cfg(feature = "nightly")]
impl<T> IndexRangesMut for T
where T: IndexMut<Range<usize>, Output = Self>
+ IndexMut<RangeTo<usize>, Output = Self>
+ IndexMut<RangeFrom<usize>, Output = Self>
+ IndexMut<RangeInclusive<usize>, Output = Self>
+ IndexMut<RangeToInclusive<usize>, Output = Self>
+ IndexMut<RangeFull, Output = Self>
{}
#[cfg(not(feature = "nightly"))]
pub trait IndexRangesMut: IndexMut<Range<usize>, Output = Self>
+ IndexMut<RangeTo<usize>, Output = Self>
+ IndexMut<RangeFrom<usize>, Output = Self>
+ IndexMut<RangeFull, Output = Self> {}
#[cfg(not(feature = "nightly"))]
impl<T> IndexRangesMut for T
where T: IndexMut<Range<usize>, Output = Self>
+ IndexMut<RangeTo<usize>, Output = Self>
+ IndexMut<RangeFrom<usize>, Output = Self>
+ IndexMut<RangeFull, Output = Self>
{}
pub trait SplitAt: Len + IndexRanges {
fn split_at(&self, index: usize) -> (&Self, &Self);
fn split_at_mut(&mut self, index: usize) -> (&mut Self, &mut Self);
}
pub trait SplitOff: LenMut {
fn split_off(&mut self, index: usize) -> Self;
}