Skip to content

Commit

Permalink
⚗️ (tracing-msg): 优化Role的结构
Browse files Browse the repository at this point in the history
  • Loading branch information
czy-29 committed Jan 13, 2025
1 parent 1a6f80a commit dee0c9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tracing-surreal/src/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<C: Connection> StopBuilder<C> {
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;
Expand Down
37 changes: 27 additions & 10 deletions tracing-surreal/src/tracing_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,22 +421,39 @@ impl From<MsgBody> 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,
}
}
Expand All @@ -445,9 +462,9 @@ impl Role {
impl From<ClientRole> 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(),
}
}
}
Expand Down

0 comments on commit dee0c9a

Please sign in to comment.