Skip to content

Commit

Permalink
refactor: remove Display impl from Sid
Browse files Browse the repository at this point in the history
  • Loading branch information
evdokimovs committed Oct 4, 2024
1 parent d1c43ca commit 8a2e41a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions proto/control-api/src/control/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{
cmp::Ordering,
collections::HashMap,
fmt,
fmt::Write as _,
hash::{Hash, Hasher},
time::Duration,
};
Expand Down Expand Up @@ -152,13 +152,21 @@ pub struct Sid {
pub creds: Option<PlainCredentials>,
}

impl Display for Sid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}/{}/{}", self.public_url, self.room_id, self.member_id)?;
impl Sid {
/// Exposes [Sid] to connect to a media server with a credentials.
pub fn expose(&self) -> String {
let mut sid = String::new();
write!(
sid,
"{}/{}/{}",
self.public_url, self.room_id, self.member_id
)
.expect("write to `String` never fails");
if let Some(plain) = &self.creds {
write!(f, "?token={}", plain.expose_str())?;
write!(sid, "?token={}", plain.expose_str())
.expect("write to `String` never fails");
}
Ok(())
sid
}
}

Expand Down
4 changes: 2 additions & 2 deletions proto/control-api/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
Ok(sids) => control_proto::CreateResponse {
sid: sids
.into_iter()
.map(|(id, sid)| (id.to_string(), sid.to_string()))
.map(|(id, sid)| (id.to_string(), sid.expose()))
.collect(),
error: None,
},
Expand Down Expand Up @@ -129,7 +129,7 @@ where
Ok(sids) => control_proto::CreateResponse {
sid: sids
.into_iter()
.map(|(id, sid)| (id.to_string(), sid.to_string()))
.map(|(id, sid)| (id.to_string(), sid.expose()))
.collect(),
error: None,
},
Expand Down

0 comments on commit 8a2e41a

Please sign in to comment.