Skip to main content

hara_native/lang/protocol/
iobjtype.rs

1use super::{IDisplay, IMetadata};
2use hara_protocol_macros::hara_protocol;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum ObjType {
6    Class,
7    Type,
8    Nil,
9    Boolean,
10    Number,
11    Character,
12    String,
13    Symbol,
14    Keyword,
15    Pattern,
16    Date,
17    Uuid,
18    Uri,
19    Sequential,
20    List,
21    Vector,
22    MapEntry,
23    Map,
24    Set,
25    Function,
26    Atom,
27    Meta,
28    Object,
29    Iterator,
30    Future,
31    Promise,
32    Delay,
33    Pending,
34    Error,
35    Reader,
36    Pointer,
37}
38
39#[hara_protocol(
40    namespace = "std.protocol.iobjtype",
41    name = "IObjType",
42    parents = ["IHash", "IDisplay"],
43    inherited_methods = [("meta", "meta", 1), ("with-meta", "with_meta", 2)]
44)]
45pub trait IObjType: IDisplay + IMetadata {
46    fn obj_type(&self) -> ObjType {
47        ObjType::Class
48    }
49
50    fn obj_name(&self) -> &'static str {
51        match self.obj_type() {
52            ObjType::Class => "CLASS",
53            ObjType::Type => "TYPE",
54            ObjType::Nil => "NIL",
55            ObjType::Boolean => "BOOLEAN",
56            ObjType::Number => "NUMBER",
57            ObjType::Character => "CHARACTER",
58            ObjType::String => "STRING",
59            ObjType::Symbol => "SYMBOL",
60            ObjType::Keyword => "KEYWORD",
61            ObjType::Pattern => "PATTERN",
62            ObjType::Date => "DATE",
63            ObjType::Uuid => "UUID",
64            ObjType::Uri => "URI",
65            ObjType::Sequential => "SEQUENTIAL",
66            ObjType::List => "LIST",
67            ObjType::Vector => "VECTOR",
68            ObjType::MapEntry => "MAP_ENTRY",
69            ObjType::Map => "MAP",
70            ObjType::Set => "SET",
71            ObjType::Function => "FUNCTION",
72            ObjType::Atom => "ATOM",
73            ObjType::Meta => "META",
74            ObjType::Object => "OBJECT",
75            ObjType::Iterator => "ITERATOR",
76            ObjType::Future => "FUTURE",
77            ObjType::Promise => "PROMISE",
78            ObjType::Delay => "DELAY",
79            ObjType::Pending => "PENDING",
80            ObjType::Error => "ERROR",
81            ObjType::Reader => "READER",
82            ObjType::Pointer => "POINTER",
83        }
84    }
85
86    fn hash_seed(&self) -> String {
87        format!("::{}", self.obj_name())
88    }
89}