use std::ops::{Range, RangeFrom, RangeTo, RangeFull};
use super::{Ixs};
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Si(pub Ixs, pub Option<Ixs>, pub Ixs);
pub trait SliceRange
{
fn slice(self) -> Si;
#[inline]
fn step(self, step: Ixs) -> Si where
Self: Sized,
{
self.slice().step(step)
}
}
impl SliceRange for Range<Ixs>
{
#[inline]
fn slice(self) -> Si { Si(self.start, Some(self.end), 1) }
}
impl SliceRange for RangeFrom<Ixs>
{
#[inline]
fn slice(self) -> Si { Si(self.start, None, 1) }
}
impl SliceRange for RangeTo<Ixs>
{
#[inline]
fn slice(self) -> Si { Si(0, Some(self.end), 1) }
}
impl SliceRange for RangeFull
{
#[inline]
fn slice(self) -> Si { Si(0, None, 1) }
}
impl Si
{
#[inline]
pub fn from<R: SliceRange>(r: R) -> Self
{
r.slice()
}
#[inline]
pub fn step(self, step: Ixs) -> Self
{
Si(self.0, self.1, self.2 * step)
}
}
pub const S: Si = Si(0, None, 1);