use std::iter::FusedIterator;
use std::slice::{Iter, IterMut};
use crate::dim::Dim;
use crate::iter::{LinearIter, LinearIterMut};
use crate::mapping::{DenseMapping, FlatMapping, GeneralMapping, Mapping, StridedMapping};
pub trait Format {
type NonUniform: Format;
type NonUnitStrided: Format;
type Uniform: Uniform;
type UnitStrided: UnitStrided;
type Format<D: Dim, F: Format>: Format;
type Iter<'a, T: 'a>: Clone
+ DoubleEndedIterator
+ ExactSizeIterator
+ FusedIterator
+ Iterator<Item = &'a T>;
type IterMut<'a, T: 'a>: DoubleEndedIterator
+ ExactSizeIterator
+ FusedIterator
+ Iterator<Item = &'a mut T>;
#[doc(hidden)]
type Mapping<D: Dim>: Mapping<Dim = D, Format = Self>;
const IS_UNIFORM: bool;
const IS_UNIT_STRIDED: bool;
}
pub trait Uniform: Format {}
pub trait UnitStrided: Format {}
pub struct Dense;
pub struct Flat;
pub struct General;
pub struct Strided;
impl Format for Dense {
type NonUniform = General;
type NonUnitStrided = Flat;
type Uniform = Self;
type UnitStrided = Self;
type Format<D: Dim, F: Format> = D::Format<F>;
type Iter<'a, T: 'a> = Iter<'a, T>;
type IterMut<'a, T: 'a> = IterMut<'a, T>;
type Mapping<D: Dim> = DenseMapping<D>;
const IS_UNIFORM: bool = true;
const IS_UNIT_STRIDED: bool = true;
}
impl Format for Flat {
type NonUniform = Strided;
type NonUnitStrided = Self;
type Uniform = Self;
type UnitStrided = Dense;
type Format<D: Dim, F: Format> = D::Format<F::NonUnitStrided>;
type Iter<'a, T: 'a> = LinearIter<'a, T>;
type IterMut<'a, T: 'a> = LinearIterMut<'a, T>;
type Mapping<D: Dim> = FlatMapping<D>;
const IS_UNIFORM: bool = true;
const IS_UNIT_STRIDED: bool = false;
}
impl Format for General {
type NonUniform = Self;
type NonUnitStrided = Strided;
type Uniform = Dense;
type UnitStrided = Self;
type Format<D: Dim, F: Format> = D::Format<F::NonUniform>;
type Iter<'a, T: 'a> = Iter<'a, T>;
type IterMut<'a, T: 'a> = IterMut<'a, T>;
type Mapping<D: Dim> = GeneralMapping<D>;
const IS_UNIFORM: bool = false;
const IS_UNIT_STRIDED: bool = true;
}
impl Format for Strided {
type NonUniform = Self;
type NonUnitStrided = Self;
type Uniform = Flat;
type UnitStrided = General;
type Format<D: Dim, F: Format> = D::Format<Self>;
type Iter<'a, T: 'a> = LinearIter<'a, T>;
type IterMut<'a, T: 'a> = LinearIterMut<'a, T>;
type Mapping<D: Dim> = StridedMapping<D>;
const IS_UNIFORM: bool = false;
const IS_UNIT_STRIDED: bool = false;
}
impl Uniform for Dense {}
impl Uniform for Flat {}
impl UnitStrided for Dense {}
impl UnitStrided for General {}