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
use crate::hash::Hash;
use crate::StaticType;
use std::fmt;

/// Type information about a value, that can be printed for human consumption
/// through its [Display][fmt::Display] implementation.
#[derive(Debug, Clone, Copy)]
pub enum TypeInfo {
    /// The static type of a value.
    StaticType(&'static StaticType),
    /// The type hash of a value.
    Hash(Hash),
    /// Reference to an external type.
    Any(&'static str),
}

impl fmt::Display for TypeInfo {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        match *self {
            Self::StaticType(ty) => {
                write!(fmt, "{}", ty.name)?;
            }
            Self::Hash(ty) => {
                write!(fmt, "Type({})", ty)?;
            }
            Self::Any(type_name) => {
                write!(fmt, "{}", type_name)?;
            }
        }

        Ok(())
    }
}