From dee0c9a54bd070b8c8b8f83082c7d555ca9d8b80 Mon Sep 17 00:00:00 2001 From: 29 <791603901@qq.com> Date: Mon, 13 Jan 2025 23:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20(tracing-msg):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96`Role`=E7=9A=84=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tracing-surreal/src/stop.rs | 2 +- tracing-surreal/src/tracing_msg.rs | 37 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tracing-surreal/src/stop.rs b/tracing-surreal/src/stop.rs index 84c8b2a..bf9ba80 100644 --- a/tracing-surreal/src/stop.rs +++ b/tracing-surreal/src/stop.rs @@ -120,7 +120,7 @@ impl StopBuilder { let session_id = rid.unwrap().id; let formatted_timestamp = a_timestamp.format("%y%m%d-%H%M%S").to_string(); let client_name = self.host; - let client_role = Role::Host; + let client_role = Role::host(); let msg_format = None; let client_addr = None; let query_map = None; diff --git a/tracing-surreal/src/tracing_msg.rs b/tracing-surreal/src/tracing_msg.rs index 483d1b5..653069c 100644 --- a/tracing-surreal/src/tracing_msg.rs +++ b/tracing-surreal/src/tracing_msg.rs @@ -421,22 +421,39 @@ impl From for TracingMsg { #[serde(rename_all = "lowercase")] pub enum Role { Host, - Pusher, - Observer, - Director, + #[serde(untagged)] + Client(ClientRole), } impl Role { + pub const fn host() -> Self { + Self::Host + } + + pub const fn pusher() -> Self { + Self::Client(ClientRole::Pusher) + } + + pub const fn observer() -> Self { + Self::Client(ClientRole::Observer) + } + + pub const fn director() -> Self { + Self::Client(ClientRole::Director) + } + pub fn can_push(&self) -> bool { - match self { - Self::Observer => false, + const OB: Role = Role::observer(); + match *self { + OB => false, _ => true, } } pub fn can_observe(&self) -> bool { - match self { - Self::Pusher => false, + const PU: Role = Role::pusher(); + match *self { + PU => false, _ => true, } } @@ -445,9 +462,9 @@ impl Role { impl From for Role { fn from(value: ClientRole) -> Self { match value { - ClientRole::Pusher => Self::Pusher, - ClientRole::Observer => Self::Observer, - ClientRole::Director => Self::Director, + ClientRole::Pusher => Self::pusher(), + ClientRole::Observer => Self::observer(), + ClientRole::Director => Self::director(), } } }