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
/// Array with an optional label struct stored next to the data. pub trait LabelledArray<E, L>: containers::CopyMap<usize, E> { /// Create a new array, with values initialized using a provided /// function, and label initialized to a provided value. fn with_label<F>(label: L, len: usize, func: F) -> Self where F: FnMut(&mut L, usize) -> E; /// Get a reference to the label. fn get_label(&self) -> &L; /// Get a reference to the element at a specified index. /// Implementations of this method shouldn't do any safety checks. unsafe fn get_unchecked(&self, idx: usize) -> &E; } /// Array with optional label struct stored next to the data that can /// be mutated pub trait LabelledArrayMut<E, L>: LabelledArray<E, L> { /// Get mutable reference to the label. fn get_label_mut(&mut self) -> &mut L; /// Get a mutable reference to the element at a specified index. /// Implementations of this method shouldn't do any safety checks. unsafe fn get_mut_unchecked(&mut self, idx: usize) -> &mut E; } /// Trait for a labelled array with a default value. pub trait DefaultLabelledArray<E, L>: LabelledArray<E, L> where E: Default, { /// Create a new array, initialized to default values. fn with_len(label: L, len: usize) -> Self; }