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
use super::slab_def::*;
use super::slab_kind::*;

#[derive(Debug, Clone, Copy)]
pub struct Slab {
    def: SlabDef,
}

impl Slab {
    pub fn new(def: SlabDef) -> Slab {
        Slab { def }
    }

    pub fn get(&self, _now_msec: i64) -> SlabKind {
        match &self.def {
            SlabDef::Void => SlabKind::Void,
            SlabDef::Floor => SlabKind::Floor,
        }
    }

    pub fn set(&mut self, def: SlabDef) {
        self.def = def
    }
}

impl std::fmt::Display for Slab {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.get(0))
    }
}

impl std::default::Default for Slab {
    fn default() -> Self {
        Self::new(SlabDef::Void)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_fmt() {
        assert_eq!(" ", format!("{}", Slab::new(SlabDef::Void)));
        assert_eq!("#", format!("{}", Slab::new(SlabDef::Floor)));
    }
}