stk/value/
value_type_info.rs

1use crate::hash::Hash;
2use std::fmt;
3
4/// Type information about a value, that can be printed for human consumption
5/// through its [Display][fmt::Display] implementation.
6#[derive(Debug, Clone, Copy)]
7pub enum ValueTypeInfo {
8    /// An empty value indicating nothing.
9    Unit,
10    /// A string.
11    String,
12    /// An array.
13    Array,
14    /// An object.
15    Object,
16    /// A number.
17    Integer,
18    /// A float.
19    Float,
20    /// A boolean.
21    Bool,
22    /// A character.
23    Char,
24    /// Reference to a foreign type.
25    External(&'static str),
26    /// The type of a value.
27    Type,
28    /// A pointer to the stack.
29    Ptr,
30    /// A function.
31    Fn(Hash),
32}
33
34impl fmt::Display for ValueTypeInfo {
35    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match *self {
37            ValueTypeInfo::Unit => {
38                write!(fmt, "unit")?;
39            }
40            ValueTypeInfo::String => {
41                write!(fmt, "String")?;
42            }
43            ValueTypeInfo::Array => {
44                write!(fmt, "Array")?;
45            }
46            ValueTypeInfo::Object => {
47                write!(fmt, "Object")?;
48            }
49            ValueTypeInfo::Integer => {
50                write!(fmt, "int")?;
51            }
52            ValueTypeInfo::Float => {
53                write!(fmt, "float")?;
54            }
55            ValueTypeInfo::Bool => {
56                write!(fmt, "bool")?;
57            }
58            ValueTypeInfo::Char => {
59                write!(fmt, "char")?;
60            }
61            ValueTypeInfo::External(type_name) => {
62                write!(fmt, "{}", type_name)?;
63            }
64            ValueTypeInfo::Type => {
65                write!(fmt, "type")?;
66            }
67            ValueTypeInfo::Ptr => {
68                write!(fmt, "ptr")?;
69            }
70            ValueTypeInfo::Fn(hash) => {
71                write!(fmt, "fn({})", hash)?;
72            }
73        }
74
75        Ok(())
76    }
77}