qualia_core_db/entity_view/
observer.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
9#[serde(rename_all = "snake_case")]
10#[repr(u8)]
11pub enum ObserverStatus {
12 #[default]
14 Principal = 0,
15 Peer = 1,
17 Guardian = 2,
19 Steward = 3,
21 Public = 4,
23 Instrument = 5,
25 Auditor = 6,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
31#[serde(rename_all = "snake_case")]
32#[repr(u8)]
33pub enum RepresentationWing {
34 #[default]
36 Private = 0,
37 Offered = 1,
39 Commons = 2,
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
45#[serde(rename_all = "snake_case")]
46#[repr(u8)]
47pub enum SensitivityClass {
48 #[default]
49 Public = 0,
50 Restricted = 1,
51 Classified = 2,
52}
53
54impl SensitivityClass {
55 pub fn parse(s: &str) -> Self {
56 match s.trim().to_ascii_lowercase().as_str() {
57 "restricted" => Self::Restricted,
58 "classified" | "sanctuary" | "secret" => Self::Classified,
59 _ => Self::Public,
60 }
61 }
62
63 pub fn is_high(self) -> bool {
64 matches!(self, Self::Restricted | Self::Classified)
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
70pub struct AffordanceBits {
71 pub can_open: bool,
72 pub can_share: bool,
73 pub can_enter: bool,
74 pub can_edit: bool,
75}
76
77impl AffordanceBits {
78 pub const NONE: Self = Self {
79 can_open: false,
80 can_share: false,
81 can_enter: false,
82 can_edit: false,
83 };
84
85 pub const FULL: Self = Self {
86 can_open: true,
87 can_share: true,
88 can_enter: true,
89 can_edit: true,
90 };
91
92 pub fn pack(self) -> u8 {
93 let mut b = 0u8;
94 if self.can_open {
95 b |= 1;
96 }
97 if self.can_share {
98 b |= 2;
99 }
100 if self.can_enter {
101 b |= 4;
102 }
103 if self.can_edit {
104 b |= 8;
105 }
106 b
107 }
108
109 pub fn unpack(b: u8) -> Self {
110 Self {
111 can_open: b & 1 != 0,
112 can_share: b & 2 != 0,
113 can_enter: b & 4 != 0,
114 can_edit: b & 8 != 0,
115 }
116 }
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
121pub struct EntityViewMeta {
122 pub entity_id: super::entity_id::EntityId,
123 pub kind: super::entity_id::EntityKind,
124 pub sensitivity: SensitivityClass,
125 pub is_secret: bool,
127 pub commons_visible: bool,
129 pub peer_offered: bool,
131}
132
133impl Default for EntityViewMeta {
134 fn default() -> Self {
135 Self {
136 entity_id: super::entity_id::EntityId::default(),
137 kind: super::entity_id::EntityKind::Unknown,
138 sensitivity: SensitivityClass::Public,
139 is_secret: false,
140 commons_visible: false,
141 peer_offered: false,
142 }
143 }
144}