From a74dddd93b3aeb11d5062361beb80b6459fecfcc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 Aug 2020 16:50:37 +0200 Subject: [PATCH] Borrow strings and identifiers in more endpoints --- ruma-client-api/src/r0/keys.rs | 14 +++++++++----- ruma-client-api/src/r0/keys/get_key_changes.rs | 8 ++++---- ruma-client-api/src/r0/keys/get_keys.rs | 2 +- .../src/r0/keys/upload_signing_keys.rs | 6 +++--- .../src/r0/to_device/send_event_to_device.rs | 2 +- .../src/r0/user_directory/search_users.rs | 18 +++++++++--------- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ruma-client-api/src/r0/keys.rs b/ruma-client-api/src/r0/keys.rs index b1bb765c..d1756f89 100644 --- a/ruma-client-api/src/r0/keys.rs +++ b/ruma-client-api/src/r0/keys.rs @@ -2,6 +2,7 @@ use std::{collections::BTreeMap, fmt::Debug}; +use ruma_api::Outgoing; use ruma_events::Algorithm; use ruma_identifiers::{DeviceId, DeviceKeyId, UserId}; use serde::{Deserialize, Serialize}; @@ -69,21 +70,24 @@ pub enum OneTimeKey { } /// A cross signing key. -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct CrossSigningKey { +#[derive(Clone, Debug, Outgoing, Serialize)] +pub struct CrossSigningKey<'a> { /// The ID of the user the key belongs to. - pub user_id: UserId, + pub user_id: &'a UserId, + /// What the key is used for. - pub usage: Vec, + pub usage: &'a [KeyUsage], + /// The public key. The object must have exactly one property. pub keys: BTreeMap, + /// Signatures of the key. Only optional for master key. #[serde(skip_serializing_if = "BTreeMap::is_empty")] pub signatures: BTreeMap>, } /// The usage of a cross signing key. -#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum KeyUsage { /// Master key. diff --git a/ruma-client-api/src/r0/keys/get_key_changes.rs b/ruma-client-api/src/r0/keys/get_key_changes.rs index c399e826..d3cc718b 100644 --- a/ruma-client-api/src/r0/keys/get_key_changes.rs +++ b/ruma-client-api/src/r0/keys/get_key_changes.rs @@ -17,21 +17,21 @@ ruma_api! { /// The desired start point of the list. /// Should be the next_batch field from a response to an earlier call to /sync. #[ruma_api(query)] - pub from: String, + pub from: &'a str, /// The desired end point of the list. /// Should be the next_batch field from a recent call to /sync - typically the most recent such call. #[ruma_api(query)] - pub to: String, + pub to: &'a str, } response: { /// The Matrix User IDs of all users who updated their device identity keys. - pub changed: Vec, + pub changed: &'a [UserId], /// The Matrix User IDs of all users who may have left all the end-to-end /// encrypted rooms they previously shared with the user. - pub left: Vec + pub left: &'a [UserId], } error: crate::Error diff --git a/ruma-client-api/src/r0/keys/get_keys.rs b/ruma-client-api/src/r0/keys/get_keys.rs index 60629ad7..ad18eea4 100644 --- a/ruma-client-api/src/r0/keys/get_keys.rs +++ b/ruma-client-api/src/r0/keys/get_keys.rs @@ -38,7 +38,7 @@ ruma_api! { /// ensure its response contains the keys advertised by the notification /// in that sync. #[serde(skip_serializing_if = "Option::is_none")] - pub token: Option, + pub token: Option<&'a str>, } response: { diff --git a/ruma-client-api/src/r0/keys/upload_signing_keys.rs b/ruma-client-api/src/r0/keys/upload_signing_keys.rs index 1f832ab8..981f1ee9 100644 --- a/ruma-client-api/src/r0/keys/upload_signing_keys.rs +++ b/ruma-client-api/src/r0/keys/upload_signing_keys.rs @@ -22,17 +22,17 @@ ruma_api! { /// The user's master key. #[serde(skip_serializing_if = "Option::is_none")] - pub master_key: Option, + pub master_key: Option>, /// The user's self-signing key. Must be signed with the accompanied master, or by the /// user's most recently uploaded master key if no master key is included in the request. #[serde(skip_serializing_if = "Option::is_none")] - pub self_signing_key: Option, + pub self_signing_key: Option>, /// The user's user-signing key. Must be signed with the accompanied master, or by the /// user's most recently uploaded master key if no master key is included in the request. #[serde(skip_serializing_if = "Option::is_none")] - pub user_signing_key: Option, + pub user_signing_key: Option>, } response: {} diff --git a/ruma-client-api/src/r0/to_device/send_event_to_device.rs b/ruma-client-api/src/r0/to_device/send_event_to_device.rs index 24207bae..5e991ba7 100644 --- a/ruma-client-api/src/r0/to_device/send_event_to_device.rs +++ b/ruma-client-api/src/r0/to_device/send_event_to_device.rs @@ -26,7 +26,7 @@ ruma_api! { /// A request identifier unique to the access token used to send the request. #[ruma_api(path)] - pub txn_id: String, + pub txn_id: &'a str, /// A map of users to devices to a content for a message event to be /// sent to the user's device. Individual message events can be sent diff --git a/ruma-client-api/src/r0/user_directory/search_users.rs b/ruma-client-api/src/r0/user_directory/search_users.rs index 033bfd4f..1dbbb17b 100644 --- a/ruma-client-api/src/r0/user_directory/search_users.rs +++ b/ruma-client-api/src/r0/user_directory/search_users.rs @@ -1,9 +1,9 @@ //! [POST /_matrix/client/r0/user_directory/search](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-user-directory-search) use js_int::{uint, UInt}; -use ruma_api::ruma_api; +use ruma_api::{ruma_api, Outgoing}; use ruma_identifiers::UserId; -use serde::{Deserialize, Serialize}; +use serde::Serialize; ruma_api! { metadata: { @@ -17,7 +17,7 @@ ruma_api! { request: { /// The term to search for. - pub search_term: String, + pub search_term: &'a str, /// The maximum number of results to return. /// @@ -28,7 +28,7 @@ ruma_api! { response: { /// Ordered by rank and then whether or not profile info is available. - pub results: Vec, + pub results: &'a [User<'a>], /// Indicates if the result list has been truncated by the limit. pub limited: bool, @@ -46,16 +46,16 @@ fn is_default_limit(limit: &UInt) -> bool { } /// User data as result of a search. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct User { +#[derive(Clone, Debug, Outgoing, Serialize)] +pub struct User<'a> { /// The user's matrix user ID. - pub user_id: UserId, + pub user_id: &'a UserId, /// The display name of the user, if one exists. #[serde(skip_serializing_if = "Option::is_none")] - pub display_name: Option, + pub display_name: Option<&'a str>, /// The avatar url, as an MXC, if one exists. #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, + pub avatar_url: Option<&'a str>, }