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
use std::ops::Deref; use std::{mem, slice}; use specs::Entity; #[derive(Default)] pub struct SpriteGuide { sorted: Vec<Entity>, } impl SpriteGuide { #[inline(always)] pub fn new() -> Self { SpriteGuide { sorted: Vec::new() } } #[inline] pub(crate) fn swap(&mut self, sorted: &mut Vec<Entity>) { mem::swap(&mut self.sorted, sorted); self.sorted.shrink_to_fit(); } #[inline(always)] pub fn as_slice(&self) -> &[Entity] { &*self.sorted } #[inline(always)] pub(crate) fn as_slice_mut(&mut self) -> &mut [Entity] { &mut *self.sorted } } impl Deref for SpriteGuide { type Target = [Entity]; #[inline(always)] fn deref(&self) -> &Self::Target { self.as_slice() } } impl<'a> IntoIterator for &'a SpriteGuide { type Item = &'a Entity; type IntoIter = slice::Iter<'a, Entity>; fn into_iter(self) -> Self::IntoIter { self.as_slice().into_iter() } }