From 277800b980460c1d08013208e401d1ff716c3695 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 18 Aug 2020 00:18:11 +0200 Subject: [PATCH] client-api: Make sync_events request and response types non-exhaustive --- ruma-client-api/src/r0/sync/sync_events.rs | 30 ++++++++++++++++++++++ ruma-client/src/lib.rs | 5 ++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ruma-client-api/src/r0/sync/sync_events.rs b/ruma-client-api/src/r0/sync/sync_events.rs index 6d7d77c9..b787283a 100644 --- a/ruma-client-api/src/r0/sync/sync_events.rs +++ b/ruma-client-api/src/r0/sync/sync_events.rs @@ -24,6 +24,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// A filter represented either as its full JSON definition or the ID of a saved filter. #[serde(skip_serializing_if = "Option::is_none")] @@ -58,6 +59,7 @@ ruma_api! { pub timeout: Option, } + #[non_exhaustive] response: { /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, @@ -93,6 +95,34 @@ ruma_api! { error: crate::Error } +impl<'a> Request<'a> { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self { + filter: None, + since: None, + full_state: false, + set_presence: Default::default(), + timeout: None, + } + } +} + +impl Response { + /// Creates a `Response` with the given batch token. + pub fn new(next_batch: String) -> Self { + Self { + next_batch, + rooms: Default::default(), + presence: Default::default(), + account_data: Default::default(), + to_device: Default::default(), + device_lists: Default::default(), + device_one_time_keys_count: BTreeMap::new(), + } + } +} + /// A filter represented either as its full JSON definition or the ID of a saved filter. #[derive(Clone, Copy, Debug, Outgoing, Serialize)] #[allow(clippy::large_enum_variant)] diff --git a/ruma-client/src/lib.rs b/ruma-client/src/lib.rs index 2e6b0e17..dedf8319 100644 --- a/ruma-client/src/lib.rs +++ b/ruma-client/src/lib.rs @@ -334,13 +334,12 @@ where async move { let response = client - .request(SyncRequest { + .request(assign!(SyncRequest::new(), { filter, since: since.as_deref(), - full_state: false, set_presence, timeout, - }) + })) .await?; let next_batch_clone = response.next_batch.clone();