Remove borrowing from API responses

To borrow these with correct lifetimes, we would need GATs
This commit is contained in:
Jonas Platte 2020-08-08 21:04:45 +02:00
parent ade12dec47
commit f37fc6845f
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
10 changed files with 35 additions and 36 deletions

View File

@ -21,10 +21,10 @@ ruma_api! {
response: { response: {
/// The room ID for this room alias. /// The room ID for this room alias.
pub room_id: &'a RoomId, pub room_id: RoomId,
/// A list of servers that are aware of this room ID. /// A list of servers that are aware of this room ID.
pub servers: &'a [String], pub servers: Vec<String>,
} }
error: crate::Error error: crate::Error

View File

@ -6,34 +6,33 @@ pub mod get_room_visibility;
pub mod set_room_visibility; pub mod set_room_visibility;
use js_int::UInt; use js_int::UInt;
use ruma_api::Outgoing;
use ruma_identifiers::{RoomAliasId, RoomId}; use ruma_identifiers::{RoomAliasId, RoomId};
use serde::Serialize; use serde::{Deserialize, Serialize};
/// A chunk of a room list response, describing one room /// A chunk of a room list response, describing one room
#[derive(Clone, Debug, Outgoing, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicRoomsChunk<'a> { pub struct PublicRoomsChunk {
/// Aliases of the room. /// Aliases of the room.
#[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<&'a RoomAliasId>, pub aliases: Vec<RoomAliasId>,
/// The canonical alias of the room, if any. /// The canonical alias of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub canonical_alias: Option<&'a RoomAliasId>, pub canonical_alias: Option<RoomAliasId>,
/// The name of the room, if any. /// The name of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<&'a str>, pub name: Option<String>,
/// The number of members joined to the room. /// The number of members joined to the room.
pub num_joined_members: UInt, pub num_joined_members: UInt,
/// The ID of the room. /// The ID of the room.
pub room_id: &'a RoomId, pub room_id: RoomId,
/// The topic of the room, if any. /// The topic of the room, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub topic: Option<&'a str>, pub topic: Option<String>,
/// Whether the room may be viewed by guest users without joining. /// Whether the room may be viewed by guest users without joining.
pub world_readable: bool, pub world_readable: bool,
@ -45,5 +44,5 @@ pub struct PublicRoomsChunk<'a> {
/// The URL for the room's avatar, if one is set. /// The URL for the room's avatar, if one is set.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<&'a str>, pub avatar_url: Option<String>,
} }

View File

@ -3,7 +3,7 @@
use js_int::UInt; use js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use super::{IncomingPublicRoomsChunk, PublicRoomsChunk}; use super::PublicRoomsChunk;
ruma_api! { ruma_api! {
metadata: { metadata: {
@ -36,13 +36,13 @@ ruma_api! {
response: { response: {
/// A paginated chunk of public rooms. /// A paginated chunk of public rooms.
pub chunk: Vec<PublicRoomsChunk<'a>>, pub chunk: Vec<PublicRoomsChunk>,
/// A pagination token for the response. /// A pagination token for the response.
pub next_batch: Option<&'a str>, pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results. /// A pagination token that allows fetching previous results.
pub prev_batch: Option<&'a str>, pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate. /// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>, pub total_room_count_estimate: Option<UInt>,
@ -73,8 +73,8 @@ fn construct_response_from_refs() {
let res: http::Response<Vec<u8>> = Response { let res: http::Response<Vec<u8>> = Response {
chunk: vec![], chunk: vec![],
next_batch: Some("next_batch_token"), next_batch: Some("next_batch_token".into()),
prev_batch: Some("prev_batch_token"), prev_batch: Some("prev_batch_token".into()),
total_room_count_estimate: Some(js_int::uint!(10)), total_room_count_estimate: Some(js_int::uint!(10)),
} }
.try_into() .try_into()

View File

@ -12,7 +12,7 @@ use serde::{
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use super::{IncomingPublicRoomsChunk, PublicRoomsChunk}; use super::PublicRoomsChunk;
ruma_api! { ruma_api! {
metadata: { metadata: {
@ -51,13 +51,13 @@ ruma_api! {
response: { response: {
/// A paginated chunk of public rooms. /// A paginated chunk of public rooms.
pub chunk: Vec<PublicRoomsChunk<'a>>, pub chunk: Vec<PublicRoomsChunk>,
/// A pagination token for the response. /// A pagination token for the response.
pub next_batch: Option<&'a str>, pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results. /// A pagination token that allows fetching previous results.
pub prev_batch: Option<&'a str>, pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate. /// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>, pub total_room_count_estimate: Option<UInt>,

View File

@ -27,11 +27,11 @@ ruma_api! {
response: { response: {
/// The Matrix User IDs of all users who updated their device identity keys. /// The Matrix User IDs of all users who updated their device identity keys.
pub changed: &'a [UserId], pub changed: Vec<UserId>,
/// The Matrix User IDs of all users who may have left all the end-to-end /// The Matrix User IDs of all users who may have left all the end-to-end
/// encrypted rooms they previously shared with the user. /// encrypted rooms they previously shared with the user.
pub left: &'a [UserId], pub left: Vec<UserId>,
} }
error: crate::Error error: crate::Error

View File

@ -41,7 +41,7 @@ ruma_api! {
response: { response: {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: &'a EventId, pub event_id: EventId,
} }
error: crate::Error error: crate::Error

View File

@ -20,7 +20,7 @@ ruma_api! {
} }
response: { response: {
aliases: &'a [RoomAliasId], aliases: Vec<RoomAliasId>,
} }
error: crate::Error error: crate::Error

View File

@ -33,7 +33,7 @@ ruma_api! {
response: { response: {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: &'a EventId, pub event_id: EventId,
} }
error: crate::Error error: crate::Error

View File

@ -37,7 +37,7 @@ ruma_api! {
response: { response: {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: &'a EventId, pub event_id: EventId,
} }
error: crate::Error error: crate::Error

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) //! [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 js_int::{uint, UInt};
use ruma_api::{ruma_api, Outgoing}; use ruma_api::ruma_api;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::Serialize; use serde::{Deserialize, Serialize};
ruma_api! { ruma_api! {
metadata: { metadata: {
@ -28,7 +28,7 @@ ruma_api! {
response: { response: {
/// Ordered by rank and then whether or not profile info is available. /// Ordered by rank and then whether or not profile info is available.
pub results: &'a [User<'a>], pub results: Vec<User>,
/// Indicates if the result list has been truncated by the limit. /// Indicates if the result list has been truncated by the limit.
pub limited: bool, pub limited: bool,
@ -46,16 +46,16 @@ fn is_default_limit(limit: &UInt) -> bool {
} }
/// User data as result of a search. /// User data as result of a search.
#[derive(Clone, Debug, Outgoing, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User<'a> { pub struct User {
/// The user's matrix user ID. /// The user's matrix user ID.
pub user_id: &'a UserId, pub user_id: UserId,
/// The display name of the user, if one exists. /// The display name of the user, if one exists.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<&'a str>, pub display_name: Option<String>,
/// The avatar url, as an MXC, if one exists. /// The avatar url, as an MXC, if one exists.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<&'a str>, pub avatar_url: Option<String>,
} }