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
//! Container for runtime type information for boxed data

use crate::class_map::ClassMap;
use crate::intern::{AsInterner, Interner};

/// Contains associated runtime type information for boxed data
///
/// This is a container for [`Interner`] and [`ClassMap`].
pub struct TypeInfo {
    interner: Interner,
    class_map: ClassMap,
}

impl TypeInfo {
    /// Constructs type information with the given components
    pub fn new(interner: Interner, class_map: ClassMap) -> TypeInfo {
        TypeInfo {
            interner,
            class_map,
        }
    }

    /// Constructs empty type information
    pub fn empty() -> TypeInfo {
        Self::new(Interner::new(), ClassMap::empty())
    }

    /// Returns a clone of this type information suitable for garbage collection
    pub fn clone_for_collect_garbage(&self) -> Self {
        Self {
            interner: self.interner.clone_for_collect_garbage(),
            class_map: self.class_map.clone(),
        }
    }

    /// Returns the symbol interner
    pub fn interner(&self) -> &Interner {
        &self.interner
    }

    /// Returns a mutable reference to the symbol interner
    pub fn interner_mut(&mut self) -> &mut Interner {
        &mut self.interner
    }

    /// Returns the class map
    pub fn class_map(&self) -> &ClassMap {
        &self.class_map
    }

    /// Returns a mutable reference to the class map
    pub fn class_map_mut(&mut self) -> &mut ClassMap {
        &mut self.class_map
    }
}

impl AsInterner for TypeInfo {
    fn as_interner(&self) -> &Interner {
        self.interner()
    }
}