Borrow strings and identifiers in more endpoints

This commit is contained in:
Jonas Platte 2020-08-08 16:50:37 +02:00
parent 6f805d2584
commit a74dddd93b
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
6 changed files with 27 additions and 23 deletions

View File

@ -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<KeyUsage>,
pub usage: &'a [KeyUsage],
/// The public key. The object must have exactly one property.
pub keys: BTreeMap<String, String>,
/// Signatures of the key. Only optional for master key.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub signatures: BTreeMap<UserId, BTreeMap<String, String>>,
}
/// 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.

View File

@ -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<UserId>,
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<UserId>
pub left: &'a [UserId],
}
error: crate::Error

View File

@ -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<String>,
pub token: Option<&'a str>,
}
response: {

View File

@ -22,17 +22,17 @@ ruma_api! {
/// The user's master key.
#[serde(skip_serializing_if = "Option::is_none")]
pub master_key: Option<CrossSigningKey>,
pub master_key: Option<CrossSigningKey<'a>>,
/// 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<CrossSigningKey>,
pub self_signing_key: Option<CrossSigningKey<'a>>,
/// 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<CrossSigningKey>,
pub user_signing_key: Option<CrossSigningKey<'a>>,
}
response: {}

View File

@ -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

View File

@ -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<User>,
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<String>,
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<String>,
pub avatar_url: Option<&'a str>,
}