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
use alloc::vec::Vec;

use core::slice;
use core::ops::Deref;

use specs::Entity;


pub struct TransformGuide {
    sorted: Vec<Entity>,
}

impl TransformGuide {
    #[inline(always)]
    pub fn new() -> Self {
        TransformGuide {
            sorted: Vec::new(),
        }
    }

    #[inline(always)]
    pub(crate) fn set(&mut self, sorted: Vec<Entity>) {
        self.sorted = sorted;
    }

    #[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 TransformGuide {
    type Target = Vec<Entity>;

    #[inline(always)]
    fn deref(&self) -> &Self::Target { &self.sorted }
}

impl<'a> IntoIterator for &'a TransformGuide {
    type Item = &'a Entity;
    type IntoIter = slice::Iter<'a, Entity>;

    fn into_iter(self) -> Self::IntoIter {
        self.as_slice().into_iter()
    }
}