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]
50 Public = 0,
51 Restricted = 1,
53 Classified = 2,
55}
56
57impl SensitivityClass {
58 pub fn parse(s: &str) -> Self {
62 match s.trim().to_ascii_lowercase().as_str() {
63 "restricted" => Self::Restricted,
64 "classified" | "sanctuary" | "secret" => Self::Classified,
65 _ => Self::Public,
66 }
67 }
68
69 pub fn is_high(self) -> bool {
72 matches!(self, Self::Restricted | Self::Classified)
73 }
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
78pub struct AffordanceBits {
79 pub can_open: bool,
81 pub can_share: bool,
83 pub can_enter: bool,
85 pub can_edit: bool,
87}
88
89impl AffordanceBits {
90 pub const NONE: Self = Self {
91 can_open: false,
92 can_share: false,
93 can_enter: false,
94 can_edit: false,
95 };
96
97 pub const FULL: Self = Self {
98 can_open: true,
99 can_share: true,
100 can_enter: true,
101 can_edit: true,
102 };
103
104 pub fn pack(self) -> u8 {
107 let mut b = 0u8;
108 if self.can_open {
109 b |= 1;
110 }
111 if self.can_share {
112 b |= 2;
113 }
114 if self.can_enter {
115 b |= 4;
116 }
117 if self.can_edit {
118 b |= 8;
119 }
120 b
121 }
122
123 pub fn unpack(b: u8) -> Self {
125 Self {
126 can_open: b & 1 != 0,
127 can_share: b & 2 != 0,
128 can_enter: b & 4 != 0,
129 can_edit: b & 8 != 0,
130 }
131 }
132}
133
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
136pub struct EntityViewMeta {
137 pub entity_id: super::entity_id::EntityId,
139 pub kind: super::entity_id::EntityKind,
141 pub sensitivity: SensitivityClass,
143 pub is_secret: bool,
145 pub commons_visible: bool,
147 pub peer_offered: bool,
149}
150
151impl Default for EntityViewMeta {
152 fn default() -> Self {
153 Self {
154 entity_id: super::entity_id::EntityId::default(),
155 kind: super::entity_id::EntityKind::Unknown,
156 sensitivity: SensitivityClass::Public,
157 is_secret: false,
158 commons_visible: false,
159 peer_offered: false,
160 }
161 }
162}