1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub enum Actor {
8 User { user_id: String },
9 ServiceUser { service_name: String },
10 System { operation: String },
11 Anonymous,
12}
13
14impl Actor {
15 pub fn is_user(&self) -> bool {
16 matches!(self, Actor::User { .. })
17 }
18
19 pub fn is_system(&self) -> bool {
20 matches!(self, Actor::System { .. })
21 }
22
23 pub fn is_anonymous(&self) -> bool {
24 matches!(self, Actor::Anonymous)
25 }
26
27 pub fn user_id(&self) -> Option<&str> {
28 match self {
29 Actor::User { user_id, .. } => Some(user_id),
30 _ => None,
31 }
32 }
33
34 #[must_use]
35 pub fn initialize_system_context() -> Self {
36 Actor::System {
37 operation: "initialize_system_context".to_string(),
38 }
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn actor_kinds() {
48 let user = Actor::User {
49 user_id: "u1".into(),
50 };
51 assert!(user.is_user());
52 assert_eq!(user.user_id(), Some("u1"));
53
54 let system = Actor::System {
55 operation: "boot".into(),
56 };
57 assert!(system.is_system());
58
59 assert!(Actor::Anonymous.is_anonymous());
60 }
61}