1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
//! Provides layerer types which are used in combination with [`Slicer`] types to determine the //! order and form in which data is produced from the layers within a [`CellMap`]. //! //! [`CellMap`]: crate::CellMap //! [`Slicer`]: crate::iterators::slicers::Slicer // ------------------------------------------------------------------------------------------------ // IMPORTS // ------------------------------------------------------------------------------------------------ use std::collections::VecDeque; use crate::Layer; // ------------------------------------------------------------------------------------------------ // TRAITS // ------------------------------------------------------------------------------------------------ /// [`Layerer`] controls how items are iterated over a [`CellMap`]s layers. /// /// [`CellMap`]: crate::CellMap pub trait Layerer<L> where L: Layer, { /// Returns the current layer. fn current(&self) -> Option<L>; } // ------------------------------------------------------------------------------------------------ // STRUCTS // ------------------------------------------------------------------------------------------------ /// Produces data from a single layer in a [`CellMap`]. /// /// [`CellMap`]: crate::CellMap pub struct Single<L> where L: Layer, { pub(crate) layer: L, } /// Produces data from many layers in a [`CellMap`] /// /// The data is produced in [`Layer::to_index()`] order. /// /// [`CellMap`]: crate::CellMap pub struct Many<L> where L: Layer, { pub(crate) layers: VecDeque<L>, } /// Produces data from two layers in pairs of `(&from, &mut to)`, allowing you to map data from one /// layer into another. pub struct Map<L> where L: Layer, { pub(crate) from: L, pub(crate) to: L, } // ------------------------------------------------------------------------------------------------ // IMPLS // ------------------------------------------------------------------------------------------------ impl<L> Layerer<L> for Single<L> where L: Layer, { fn current(&self) -> Option<L> { Some(self.layer.clone()) } } impl<L> Layerer<L> for Many<L> where L: Layer, { fn current(&self) -> Option<L> { self.layers.front().map(|l| l.clone()) } } impl<L> Layerer<L> for Map<L> where L: Layer, { fn current(&self) -> Option<L> { Some(self.from.clone()) } }