mirascript_vm/value/
type_enum.rs1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum MiraType {
6 Nil,
8 Boolean,
10 Number,
12 String,
14 Array,
16 Record,
18 Function,
20 Module,
22 Extern,
24}
25
26impl MiraType {
27 #[inline]
29 pub const fn name(self) -> &'static str {
30 match self {
31 Self::Nil => "nil",
32 Self::Boolean => "boolean",
33 Self::Number => "number",
34 Self::String => "string",
35 Self::Array => "array",
36 Self::Record => "record",
37 Self::Function => "function",
38 Self::Module => "module",
39 Self::Extern => "extern",
40 }
41 }
42}
43
44impl fmt::Display for MiraType {
45 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
46 formatter.write_str(self.name())
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn type_display() {
56 assert_eq!(MiraType::Nil.to_string(), "nil");
57 assert_eq!(MiraType::Boolean.to_string(), "boolean");
58 assert_eq!(MiraType::Number.to_string(), "number");
59 assert_eq!(MiraType::String.to_string(), "string");
60 assert_eq!(MiraType::Array.to_string(), "array");
61 assert_eq!(MiraType::Record.to_string(), "record");
62 assert_eq!(MiraType::Function.to_string(), "function");
63 assert_eq!(MiraType::Module.to_string(), "module");
64 assert_eq!(MiraType::Extern.to_string(), "extern");
65 }
66}