From 062c2cc55b9961e36c6644eb5ef5b3cdc5377191 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 16 May 2021 23:16:24 +0200 Subject: [PATCH] events: Make remaining types in call::* non-exhaustive --- crates/ruma-events/src/call/candidates.rs | 17 +++++++++++++++++ crates/ruma-events/src/call/hangup.rs | 8 ++++++++ crates/ruma-events/src/call/invite.rs | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/crates/ruma-events/src/call/candidates.rs b/crates/ruma-events/src/call/candidates.rs index 8f6424da..0c61d0a6 100644 --- a/crates/ruma-events/src/call/candidates.rs +++ b/crates/ruma-events/src/call/candidates.rs @@ -12,6 +12,7 @@ pub type CandidatesEvent = MessageEvent; /// The payload for `CandidatesEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.candidates", kind = Message)] pub struct CandidatesEventContent { /// The ID of the call this event relates to. @@ -24,8 +25,17 @@ pub struct CandidatesEventContent { pub version: UInt, } +impl CandidatesEventContent { + /// Creates a new `CandidatesEventContent` with the given call id, candidate list and VoIP + /// version. + pub fn new(call_id: String, candidates: Vec, version: UInt) -> Self { + Self { call_id, candidates, version } + } +} + /// An ICE (Interactive Connectivity Establishment) candidate. #[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(rename_all = "camelCase")] pub struct Candidate { /// The SDP "a" line of the candidate. @@ -37,3 +47,10 @@ pub struct Candidate { /// The index of the SDP "m" line this candidate is intended for. pub sdp_m_line_index: UInt, } + +impl Candidate { + /// Creates a new `Candidate` with the given "a" line, SDP media type and SDP "m" line. + pub fn new(candidate: String, sdp_mid: String, sdp_m_line_index: UInt) -> Self { + Self { candidate, sdp_mid, sdp_m_line_index } + } +} diff --git a/crates/ruma-events/src/call/hangup.rs b/crates/ruma-events/src/call/hangup.rs index a6243051..b92654d8 100644 --- a/crates/ruma-events/src/call/hangup.rs +++ b/crates/ruma-events/src/call/hangup.rs @@ -13,6 +13,7 @@ pub type HangupEvent = MessageEvent; /// The payload for `HangupEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.hangup", kind = Message)] pub struct HangupEventContent { /// The ID of the call this event relates to. @@ -26,6 +27,13 @@ pub struct HangupEventContent { pub reason: Option, } +impl HangupEventContent { + /// Creates a new `HangupEventContent` with the given call ID and VoIP version. + pub fn new(call_id: String, version: UInt) -> Self { + Self { call_id, version, reason: None } + } +} + /// A reason for a hangup. /// /// This should not be provided when the user naturally ends or rejects the call. When there was an diff --git a/crates/ruma-events/src/call/invite.rs b/crates/ruma-events/src/call/invite.rs index 169b359e..97ab421d 100644 --- a/crates/ruma-events/src/call/invite.rs +++ b/crates/ruma-events/src/call/invite.rs @@ -12,6 +12,7 @@ pub type InviteEvent = MessageEvent; /// The payload for `InviteEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.call.invite", kind = Message)] pub struct InviteEventContent { /// A unique identifier for the call. @@ -28,3 +29,10 @@ pub struct InviteEventContent { /// The version of the VoIP specification this messages adheres to. pub version: UInt, } + +impl InviteEventContent { + /// Creates a new `InviteEventContent` with the given call ID, lifetime and VoIP version. + pub fn new(call_id: String, lifetime: UInt, offer: SessionDescription, version: UInt) -> Self { + Self { call_id, lifetime, offer, version } + } +}