diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d01912f1..8e8e4a67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -213,57 +213,6 @@ guidelines: - If you're not sure what to name it, pick any name and we can help you with it. -### Borrowing Request Types - -In order to reduce the number of `.clone()`s necessary to send requests -to a server, we support borrowed types for request types. (We hope to support -borrowing in response types sometime, but that is dependent on GATs.) - -#### Types to borrow - -| Field type | Borrowed type | Notes | -| ---------- | ------------- | ----- | -| strings | `&'a str` | | -| identifiers | `&'a IdentifierType` | | -| `Vec<_>` | `&'a [_]` | The inner type should not be borrowed. | - -#### Types not to borrow - -Inner types of `Vec`s _should not_ be borrowed, nor should `BTreeMap`s and such. - -Structs also should not be borrowed, with the exception that if a struct: - -- has fields that should be borrowed according to the table -above (strings, identifiers, `Vec`s), and -- is only used inside request blocks (i.e. not in response blocks or in events), - -then the struct should be lifetime-parameterized and apply the same rules to -their fields. So instead of - -```rust -#[request] -pub struct Request { - my_field: MyStruct, -} - -pub struct MyStruct { - inner_string_field: String, -} -``` - -use - -```rust -#[request] -pub struct Request<'a> { - my_field: MyStruct<'a>, -} - -pub struct MyStruct<'a> { - inner_string_field: &'a str, -} -``` - ### Tracking Changes If your changes affect the API of a user-facing crate (all except the `-macros` crates and diff --git a/crates/ruma-appservice-api/src/event/push_events.rs b/crates/ruma-appservice-api/src/event/push_events.rs index 73d0d7ea..80ba85fc 100644 --- a/crates/ruma-appservice-api/src/event/push_events.rs +++ b/crates/ruma-appservice-api/src/event/push_events.rs @@ -21,7 +21,7 @@ pub mod v1 { events::AnyTimelineEvent, metadata, serde::Raw, - OwnedTransactionId, TransactionId, + OwnedTransactionId, }; #[cfg(feature = "unstable-msc2409")] use ruma_common::{ @@ -48,15 +48,15 @@ pub mod v1 { /// Request type for the `push_events` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The transaction ID for this set of events. /// /// Homeservers generate these IDs and they are used to ensure idempotency of results. #[ruma_api(path)] - pub txn_id: &'a TransactionId, + pub txn_id: OwnedTransactionId, /// A list of events. - pub events: &'a [Raw], + pub events: Vec>, /// Information on E2E device updates. #[cfg(feature = "unstable-msc3202")] @@ -96,7 +96,7 @@ pub mod v1 { skip_serializing_if = "<[_]>::is_empty", rename = "de.sorunome.msc2409.ephemeral" )] - pub ephemeral: &'a [Edu], + pub ephemeral: Vec, /// A list of to-device messages. #[cfg(feature = "unstable-msc2409")] @@ -105,7 +105,7 @@ pub mod v1 { skip_serializing_if = "<[_]>::is_empty", rename = "de.sorunome.msc2409.to_device" )] - pub to_device: &'a [Raw], + pub to_device: Vec>, } /// Response type for the `push_events` endpoint. @@ -113,33 +113,10 @@ pub mod v1 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { - /// Creates a new `Request` with the given transaction ID and list of events. - pub fn new(txn_id: &'a TransactionId, events: &'a [Raw]) -> Self { - Self { - txn_id, - events, - #[cfg(feature = "unstable-msc3202")] - device_lists: DeviceLists::new(), - #[cfg(feature = "unstable-msc3202")] - device_one_time_keys_count: BTreeMap::new(), - #[cfg(feature = "unstable-msc3202")] - device_unused_fallback_key_types: BTreeMap::new(), - #[cfg(feature = "unstable-msc2409")] - ephemeral: &[], - #[cfg(feature = "unstable-msc2409")] - to_device: &[], - } - } - } - - impl IncomingRequest { - /// Creates an `IncomingRequest` with the given transaction ID and list of events. - pub fn new( - txn_id: OwnedTransactionId, - events: Vec>, - ) -> IncomingRequest { - IncomingRequest { + impl Request { + /// Creates an `Request` with the given transaction ID and list of events. + pub fn new(txn_id: OwnedTransactionId, events: Vec>) -> Request { + Request { txn_id, events, #[cfg(feature = "unstable-msc3202")] @@ -393,7 +370,7 @@ pub mod v1 { .unwrap(); let events = vec![dummy_event]; - let req = Request::new("any_txn_id".into(), &events) + let req = Request::new("any_txn_id".into(), events) .try_into_http_request::>( "https://homeserver.tld", SendAccessToken::IfRequired("auth_tok"), diff --git a/crates/ruma-appservice-api/src/query/query_room_alias.rs b/crates/ruma-appservice-api/src/query/query_room_alias.rs index b6f9eaa2..b4269dac 100644 --- a/crates/ruma-appservice-api/src/query/query_room_alias.rs +++ b/crates/ruma-appservice-api/src/query/query_room_alias.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomAliasId, + metadata, OwnedRoomAliasId, }; const METADATA: Metadata = metadata! { @@ -23,10 +23,10 @@ pub mod v1 { /// Request type for the `query_room_alias` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room alias being queried. #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + pub room_alias: OwnedRoomAliasId, } /// Response type for the `query_room_alias` endpoint. @@ -34,9 +34,9 @@ pub mod v1 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias. - pub fn new(room_alias: &'a RoomAliasId) -> Self { + pub fn new(room_alias: OwnedRoomAliasId) -> Self { Self { room_alias } } } diff --git a/crates/ruma-appservice-api/src/query/query_user_id.rs b/crates/ruma-appservice-api/src/query/query_user_id.rs index 999e28b7..02b0fb96 100644 --- a/crates/ruma-appservice-api/src/query/query_user_id.rs +++ b/crates/ruma-appservice-api/src/query/query_user_id.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, UserId, + metadata, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -23,10 +23,10 @@ pub mod v1 { /// Request type for the `query_user_id` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The user ID being queried. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `query_user_id` endpoint. @@ -34,9 +34,9 @@ pub mod v1 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs index d140a1ba..d9161a90 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs @@ -26,10 +26,10 @@ pub mod v1 { /// Request type for the `get_location_for_protocol` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The protocol used to communicate to the third party network. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). @@ -45,9 +45,9 @@ pub mod v1 { pub locations: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol, fields: BTreeMap::new() } } } diff --git a/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs b/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs index a34138a3..86a8b7b5 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs @@ -11,7 +11,7 @@ pub mod v1 { api::{request, response, Metadata}, metadata, thirdparty::Location, - RoomAliasId, + OwnedRoomAliasId, }; const METADATA: Metadata = metadata! { @@ -25,10 +25,10 @@ pub mod v1 { /// Request type for the `get_location_for_room_alias` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The Matrix room alias to look up. #[ruma_api(query)] - pub alias: &'a RoomAliasId, + pub alias: OwnedRoomAliasId, } /// Response type for the `get_location_for_room_alias` endpoint. @@ -39,9 +39,9 @@ pub mod v1 { pub locations: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias id. - pub fn new(alias: &'a RoomAliasId) -> Self { + pub fn new(alias: OwnedRoomAliasId) -> Self { Self { alias } } } diff --git a/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs index 36a37aa9..fce41383 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs @@ -24,10 +24,10 @@ pub mod v1 { /// Request type for the `get_protocol` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The name of the protocol. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, } /// Response type for the `get_protocol` endpoint. @@ -38,9 +38,9 @@ pub mod v1 { pub protocol: Protocol, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol name. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol } } } diff --git a/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs index 6f122e86..2ff91ae8 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs @@ -27,10 +27,10 @@ pub mod v1 { /// Request type for the `get_user_for_protocol` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The protocol used to communicate to the third party network. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). @@ -46,9 +46,9 @@ pub mod v1 { pub users: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol name. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol, fields: BTreeMap::new() } } } diff --git a/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs b/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs index f2c53d5f..5b3fdcef 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs @@ -11,7 +11,7 @@ pub mod v1 { api::{request, response, Metadata}, metadata, thirdparty::User, - UserId, + OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -25,10 +25,10 @@ pub mod v1 { /// Request type for the `get_user_for_user_id` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The Matrix User ID to look up. #[ruma_api(query)] - pub userid: &'a UserId, + pub userid: OwnedUserId, } /// Response type for the `get_user_for_user_id` endpoint. @@ -39,9 +39,9 @@ pub mod v1 { pub users: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(userid: &'a UserId) -> Self { + pub fn new(userid: OwnedUserId) -> Self { Self { userid } } } diff --git a/crates/ruma-client-api/src/account.rs b/crates/ruma-client-api/src/account.rs index 72d181ea..402fbd72 100644 --- a/crates/ruma-client-api/src/account.rs +++ b/crates/ruma-client-api/src/account.rs @@ -19,26 +19,26 @@ pub mod request_registration_token_via_msisdn; pub mod unbind_3pid; pub mod whoami; -use ruma_common::serde::{Incoming, StringEnum}; -use serde::Serialize; +use ruma_common::serde::StringEnum; +use serde::{Deserialize, Serialize}; use crate::PrivOwnedStr; /// Additional authentication information for requestToken endpoints. -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct IdentityServerInfo<'a> { +pub struct IdentityServerInfo { /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. - pub id_server: &'a str, + pub id_server: String, /// Access token previously registered with identity server. - pub id_access_token: &'a str, + pub id_access_token: String, } -impl<'a> IdentityServerInfo<'a> { +impl IdentityServerInfo { /// Creates a new `IdentityServerInfo` with the given server name and access token. - pub fn new(id_server: &'a str, id_access_token: &'a str) -> Self { + pub fn new(id_server: String, id_access_token: String) -> Self { Self { id_server, id_access_token } } } diff --git a/crates/ruma-client-api/src/account/add_3pid.rs b/crates/ruma-client-api/src/account/add_3pid.rs index f70defb5..6c3d2b49 100644 --- a/crates/ruma-client-api/src/account/add_3pid.rs +++ b/crates/ruma-client-api/src/account/add_3pid.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: POST, @@ -26,16 +26,16 @@ pub mod v3 { /// Request type for the `add_3pid` endpoint. #[request(error = UiaaResponse)] - pub struct Request<'a> { + pub struct Request { /// Additional information for the User-Interactive Authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The session identifier given by the identity server. - pub sid: &'a SessionId, + pub sid: OwnedSessionId, } /// Response type for the `add_3pid` endpoint. @@ -43,9 +43,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret and session identifier. - pub fn new(client_secret: &'a ClientSecret, sid: &'a SessionId) -> Self { + pub fn new(client_secret: OwnedClientSecret, sid: OwnedSessionId) -> Self { Self { auth: None, client_secret, sid } } } diff --git a/crates/ruma-client-api/src/account/bind_3pid.rs b/crates/ruma-client-api/src/account/bind_3pid.rs index 26ae51c2..9bd03d2f 100644 --- a/crates/ruma-client-api/src/account/bind_3pid.rs +++ b/crates/ruma-client-api/src/account/bind_3pid.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -26,17 +26,17 @@ pub mod v3 { /// Request type for the `bind_3pid` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The ID server to send the onward request to as a hostname with an /// appended colon and port number if the port is not the default. #[serde(flatten)] - pub identity_server_info: IdentityServerInfo<'a>, + pub identity_server_info: IdentityServerInfo, /// The session identifier given by the identity server. - pub sid: &'a SessionId, + pub sid: OwnedSessionId, } /// Response type for the `bind_3pid` endpoint. @@ -44,13 +44,13 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, identity server information and /// session identifier. pub fn new( - client_secret: &'a ClientSecret, - identity_server_info: IdentityServerInfo<'a>, - sid: &'a SessionId, + client_secret: OwnedClientSecret, + identity_server_info: IdentityServerInfo, + sid: OwnedSessionId, ) -> Self { Self { client_secret, identity_server_info, sid } } diff --git a/crates/ruma-client-api/src/account/change_password.rs b/crates/ruma-client-api/src/account/change_password.rs index 609e0a86..5d0da986 100644 --- a/crates/ruma-client-api/src/account/change_password.rs +++ b/crates/ruma-client-api/src/account/change_password.rs @@ -12,7 +12,7 @@ pub mod v3 { metadata, }; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: POST, @@ -26,9 +26,9 @@ pub mod v3 { /// Request type for the `change_password` endpoint. #[request(error = UiaaResponse)] - pub struct Request<'a> { + pub struct Request { /// The new password for the account. - pub new_password: &'a str, + pub new_password: String, /// True to revoke the user's other access tokens, and their associated devices if the /// request succeeds. @@ -45,7 +45,7 @@ pub mod v3 { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, } /// Response type for the `change_password` endpoint. @@ -53,9 +53,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given password. - pub fn new(new_password: &'a str) -> Self { + pub fn new(new_password: String) -> Self { Self { new_password, logout_devices: true, auth: None } } } diff --git a/crates/ruma-client-api/src/account/check_registration_token_validity.rs b/crates/ruma-client-api/src/account/check_registration_token_validity.rs index e6a50cf8..aa235092 100644 --- a/crates/ruma-client-api/src/account/check_registration_token_validity.rs +++ b/crates/ruma-client-api/src/account/check_registration_token_validity.rs @@ -24,10 +24,10 @@ pub mod v1 { /// Request type for the `check_registration_token_validity` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The registration token to check the validity of. #[ruma_api(query)] - pub registration_token: &'a str, + pub registration_token: String, } /// Response type for the `check_registration_token_validity` endpoint. @@ -37,9 +37,9 @@ pub mod v1 { pub valid: bool, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given registration token. - pub fn new(registration_token: &'a str) -> Self { + pub fn new(registration_token: String) -> Self { Self { registration_token } } } diff --git a/crates/ruma-client-api/src/account/deactivate.rs b/crates/ruma-client-api/src/account/deactivate.rs index 24c509d8..619d848e 100644 --- a/crates/ruma-client-api/src/account/deactivate.rs +++ b/crates/ruma-client-api/src/account/deactivate.rs @@ -14,7 +14,7 @@ pub mod v3 { use crate::{ account::ThirdPartyIdRemovalStatus, - uiaa::{AuthData, IncomingAuthData, UiaaResponse}, + uiaa::{AuthData, UiaaResponse}, }; const METADATA: Metadata = metadata! { @@ -30,15 +30,15 @@ pub mod v3 { /// Request type for the `deactivate` endpoint. #[request(error = UiaaResponse)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, /// Identity server from which to unbind the user's third party /// identifier. #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, + pub id_server: Option, } /// Response type for the `deactivate` endpoint. @@ -48,7 +48,7 @@ pub mod v3 { pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/account/delete_3pid.rs b/crates/ruma-client-api/src/account/delete_3pid.rs index 18739c64..0956e2b8 100644 --- a/crates/ruma-client-api/src/account/delete_3pid.rs +++ b/crates/ruma-client-api/src/account/delete_3pid.rs @@ -27,16 +27,16 @@ pub mod v3 { /// Request type for the `delete_3pid` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Identity server to delete from. #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, + pub id_server: Option, /// Medium of the 3PID to be removed. pub medium: Medium, /// Third-party address being removed. - pub address: &'a str, + pub address: String, } /// Response type for the `delete_3pid` endpoint. @@ -46,9 +46,9 @@ pub mod v3 { pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given medium and address. - pub fn new(medium: Medium, address: &'a str) -> Self { + pub fn new(medium: Medium, address: String) -> Self { Self { id_server: None, medium, address } } } diff --git a/crates/ruma-client-api/src/account/get_username_availability.rs b/crates/ruma-client-api/src/account/get_username_availability.rs index e4a462c0..ae590c2e 100644 --- a/crates/ruma-client-api/src/account/get_username_availability.rs +++ b/crates/ruma-client-api/src/account/get_username_availability.rs @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `get_username_availability` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The username to check the availability of. #[ruma_api(query)] - pub username: &'a str, + pub username: String, } /// Response type for the `get_username_availability` endpoint. @@ -38,9 +38,9 @@ pub mod v3 { pub available: bool, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given username. - pub fn new(username: &'a str) -> Self { + pub fn new(username: String) -> Self { Self { username } } } diff --git a/crates/ruma-client-api/src/account/register.rs b/crates/ruma-client-api/src/account/register.rs index a3c4cffa..04bff43d 100644 --- a/crates/ruma-client-api/src/account/register.rs +++ b/crates/ruma-client-api/src/account/register.rs @@ -13,11 +13,11 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, DeviceId, OwnedDeviceId, OwnedUserId, + metadata, OwnedDeviceId, OwnedUserId, }; use super::{LoginType, RegistrationKind}; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: POST, @@ -32,32 +32,32 @@ pub mod v3 { /// Request type for the `register` endpoint. #[request(error = UiaaResponse)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// The desired password for the account. /// /// May be empty for accounts that should not be able to log in again /// with a password, e.g., for guest or application service accounts. #[serde(skip_serializing_if = "Option::is_none")] - pub password: Option<&'a str>, + pub password: Option, /// Localpart of the desired Matrix ID. /// /// If omitted, the homeserver MUST generate a Matrix ID local part. #[serde(skip_serializing_if = "Option::is_none")] - pub username: Option<&'a str>, + pub username: Option, /// ID of the client device. /// /// If this does not correspond to a known client device, a new device will be created. /// The server will auto-generate a device_id if this is not specified. #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, + pub device_id: Option, /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, + pub initial_device_display_name: Option, /// Additional authentication information for the user-interactive authentication API. /// @@ -66,7 +66,7 @@ pub mod v3 { /// It should be left empty, or omitted, unless an earlier call returned an response /// with status code 401. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, /// Kind of account to register /// @@ -87,7 +87,7 @@ pub mod v3 { /// /// [admin]: https://spec.matrix.org/v1.4/application-service-api/#server-admin-style-permissions #[serde(rename = "type", skip_serializing_if = "Option::is_none")] - pub login_type: Option<&'a LoginType>, + pub login_type: Option, /// If set to `true`, the client supports [refresh tokens]. /// @@ -147,7 +147,7 @@ pub mod v3 { pub expires_in: Option, } - impl Request<'_> { + impl Request { /// Creates a new `Request` with all parameters defaulted. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs b/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs index 1f5426e7..699d9599 100644 --- a/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs @@ -10,10 +10,10 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -27,25 +27,25 @@ pub mod v3 { /// Request type for the `request_3pid_management_token_via_email` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The email address. - pub email: &'a str, + pub email: String, /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, /// Optional identity server hostname and access token. /// /// Deprecated since r0.6.0. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, + pub identity_server_info: Option, } /// Response type for the `request_3pid_management_token_via_email` endpoint. @@ -68,9 +68,9 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the client secret, email and send-attempt counter. - pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self { + pub fn new(client_secret: OwnedClientSecret, email: String, send_attempt: UInt) -> Self { Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None } } } diff --git a/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs index 1faf9519..26472378 100644 --- a/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs @@ -10,10 +10,10 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -27,28 +27,28 @@ pub mod v3 { /// Request type for the `request_3pid_management_token_via_msisdn` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + pub country: String, /// Phone number to validate. - pub phone_number: &'a str, + pub phone_number: String, /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, /// Optional identity server hostname and access token. /// /// Deprecated since r0.6.0. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, + pub identity_server_info: Option, } /// Response type for the `request_3pid_management_token_via_msisdn` endpoint. @@ -71,13 +71,13 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, country code, phone number and /// send-attempt counter. pub fn new( - client_secret: &'a ClientSecret, - country: &'a str, - phone_number: &'a str, + client_secret: OwnedClientSecret, + country: String, + phone_number: String, send_attempt: UInt, ) -> Self { Self { diff --git a/crates/ruma-client-api/src/account/request_openid_token.rs b/crates/ruma-client-api/src/account/request_openid_token.rs index 6bedc600..e997bacf 100644 --- a/crates/ruma-client-api/src/account/request_openid_token.rs +++ b/crates/ruma-client-api/src/account/request_openid_token.rs @@ -12,7 +12,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, authentication::TokenType, - metadata, OwnedServerName, UserId, + metadata, OwnedServerName, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `request_openid_token` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// User ID of authenticated user. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `request_openid_token` endpoint. @@ -50,9 +50,9 @@ pub mod v3 { pub expires_in: Duration, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs b/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs index 9d62b70c..368bc3b9 100644 --- a/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs @@ -10,10 +10,10 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -27,25 +27,25 @@ pub mod v3 { /// Request type for the `request_password_change_token_via_email` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The email address. - pub email: &'a str, + pub email: String, /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, /// Optional identity server hostname and access token. /// /// Deprecated since r0.6.0. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, + pub identity_server_info: Option, } /// Response type for the `request_password_change_token_via_email` endpoint. @@ -68,10 +68,10 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, email address and send-attempt /// counter. - pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self { + pub fn new(client_secret: OwnedClientSecret, email: String, send_attempt: UInt) -> Self { Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None } } } diff --git a/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs index e097b7f6..4836d718 100644 --- a/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs @@ -10,7 +10,7 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -25,22 +25,22 @@ pub mod v3 { /// Request type for the `request_password_change_token_via_msisdn` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + pub country: String, /// Phone number to validate. - pub phone_number: &'a str, + pub phone_number: String, /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, } /// Response type for the `request_password_change_token_via_msisdn` endpoint. @@ -63,13 +63,13 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, country code, phone number and /// send-attempt counter. pub fn new( - client_secret: &'a ClientSecret, - country: &'a str, - phone_number: &'a str, + client_secret: OwnedClientSecret, + country: String, + phone_number: String, send_attempt: UInt, ) -> Self { Self { client_secret, country, phone_number, send_attempt, next_link: None } diff --git a/crates/ruma-client-api/src/account/request_registration_token_via_email.rs b/crates/ruma-client-api/src/account/request_registration_token_via_email.rs index 92e26426..ee1ba8a5 100644 --- a/crates/ruma-client-api/src/account/request_registration_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_registration_token_via_email.rs @@ -10,10 +10,10 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -27,25 +27,25 @@ pub mod v3 { /// Request type for the `request_registration_token_via_email` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The email address. - pub email: &'a str, + pub email: String, /// Used to distinguish protocol level retries from requests to re-send the email. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, /// Optional identity server hostname and access token. /// /// Deprecated since r0.6.0. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, + pub identity_server_info: Option, } /// Response type for the `request_registration_token_via_email` endpoint. @@ -68,10 +68,10 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, email address and send-attempt /// counter. - pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self { + pub fn new(client_secret: OwnedClientSecret, email: String, send_attempt: UInt) -> Self { Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None } } } diff --git a/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs index 6c737d84..03f248cc 100644 --- a/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs @@ -10,10 +10,10 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; - use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; + use crate::account::IdentityServerInfo; const METADATA: Metadata = metadata! { method: POST, @@ -27,28 +27,28 @@ pub mod v3 { /// Request type for the `request_registration_token_via_msisdn` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + pub country: String, /// Phone number to validate. - pub phone_number: &'a str, + pub phone_number: String, /// Used to distinguish protocol level retries from requests to re-send the SMS. pub send_attempt: UInt, /// Return URL for identity server to redirect the client back to. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, /// Optional identity server hostname and access token. /// /// Deprecated since r0.6.0. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, + pub identity_server_info: Option, } /// Response type for the `request_registration_token_via_msisdn` endpoint. @@ -71,13 +71,13 @@ pub mod v3 { pub submit_url: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given client secret, country code, phone number and /// send-attempt counter. pub fn new( - client_secret: &'a ClientSecret, - country: &'a str, - phone_number: &'a str, + client_secret: OwnedClientSecret, + country: String, + phone_number: String, send_attempt: UInt, ) -> Self { Self { diff --git a/crates/ruma-client-api/src/account/unbind_3pid.rs b/crates/ruma-client-api/src/account/unbind_3pid.rs index 799e2792..d42bf857 100644 --- a/crates/ruma-client-api/src/account/unbind_3pid.rs +++ b/crates/ruma-client-api/src/account/unbind_3pid.rs @@ -27,16 +27,16 @@ pub mod v3 { /// Request type for the `unbind_3pid` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Identity server to unbind from. #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, + pub id_server: Option, /// Medium of the 3PID to be removed. pub medium: Medium, /// Third-party address being removed. - pub address: &'a str, + pub address: String, } /// Response type for the `unbind_3pid` endpoint. @@ -46,9 +46,9 @@ pub mod v3 { pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given medium and third-party address. - pub fn new(medium: Medium, address: &'a str) -> Self { + pub fn new(medium: Medium, address: String) -> Self { Self { id_server: None, medium, address } } } diff --git a/crates/ruma-client-api/src/alias/create_alias.rs b/crates/ruma-client-api/src/alias/create_alias.rs index 97e07884..34b6c81f 100644 --- a/crates/ruma-client-api/src/alias/create_alias.rs +++ b/crates/ruma-client-api/src/alias/create_alias.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomAliasId, RoomId, + metadata, OwnedRoomAliasId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -24,13 +24,13 @@ pub mod v3 { /// Request type for the `create_alias` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room alias to set. #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + pub room_alias: OwnedRoomAliasId, /// The room ID to set. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `create_alias` endpoint. @@ -38,9 +38,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias and room id. - pub fn new(room_alias: &'a RoomAliasId, room_id: &'a RoomId) -> Self { + pub fn new(room_alias: OwnedRoomAliasId, room_id: OwnedRoomId) -> Self { Self { room_alias, room_id } } } diff --git a/crates/ruma-client-api/src/alias/delete_alias.rs b/crates/ruma-client-api/src/alias/delete_alias.rs index 0f1a8cf2..4fae8156 100644 --- a/crates/ruma-client-api/src/alias/delete_alias.rs +++ b/crates/ruma-client-api/src/alias/delete_alias.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomAliasId, + metadata, OwnedRoomAliasId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `delete_alias` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room alias to remove. #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + pub room_alias: OwnedRoomAliasId, } /// Response type for the `delete_alias` endpoint. @@ -35,9 +35,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias. - pub fn new(room_alias: &'a RoomAliasId) -> Self { + pub fn new(room_alias: OwnedRoomAliasId) -> Self { Self { room_alias } } } diff --git a/crates/ruma-client-api/src/alias/get_alias.rs b/crates/ruma-client-api/src/alias/get_alias.rs index 16fd7c47..015b4948 100644 --- a/crates/ruma-client-api/src/alias/get_alias.rs +++ b/crates/ruma-client-api/src/alias/get_alias.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, OwnedServerName, RoomAliasId, + metadata, OwnedRoomAliasId, OwnedRoomId, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `get_alias` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room alias. #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + pub room_alias: OwnedRoomAliasId, } /// Response type for the `get_alias` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { pub servers: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias id. - pub fn new(room_alias: &'a RoomAliasId) -> Self { + pub fn new(room_alias: OwnedRoomAliasId) -> Self { Self { room_alias } } } diff --git a/crates/ruma-client-api/src/appservice/set_room_visibility.rs b/crates/ruma-client-api/src/appservice/set_room_visibility.rs index deb2fb9b..32c52f4a 100644 --- a/crates/ruma-client-api/src/appservice/set_room_visibility.rs +++ b/crates/ruma-client-api/src/appservice/set_room_visibility.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; use crate::room::Visibility; @@ -26,14 +26,14 @@ pub mod v3 { /// Request type for the `set_room_visibility` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The protocol (network) ID to update the room list for. #[ruma_api(path)] - pub network_id: &'a str, + pub network_id: String, /// The room ID to add to the directory. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// Whether the room should be visible (public) in the directory or not (private). pub visibility: Visibility, @@ -44,9 +44,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given network ID, room ID and visibility. - pub fn new(network_id: &'a str, room_id: &'a RoomId, visibility: Visibility) -> Self { + pub fn new(network_id: String, room_id: OwnedRoomId, visibility: Visibility) -> Self { Self { network_id, room_id, visibility } } } diff --git a/crates/ruma-client-api/src/backup/add_backup_keys.rs b/crates/ruma-client-api/src/backup/add_backup_keys.rs index 83f9df15..8b8b7ac5 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys.rs @@ -29,12 +29,12 @@ pub mod v3 { /// Request type for the `add_backup_keys` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to add keys to. /// /// Must be the current backup. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// A map of room IDs to session IDs to key data to store. pub rooms: BTreeMap, @@ -53,9 +53,9 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version and room key backups. - pub fn new(version: &'a str, rooms: BTreeMap) -> Self { + pub fn new(version: String, rooms: BTreeMap) -> Self { Self { version, rooms } } } diff --git a/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs index be9a7bbd..b1212ddd 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs @@ -14,7 +14,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; use crate::backup::KeyBackupData; @@ -32,16 +32,16 @@ pub mod v3 { /// Request type for the `add_backup_keys_for_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to add keys to. /// /// Must be the current backup. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room to add keys to. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// A map of session IDs to key data to store. pub sessions: BTreeMap>, @@ -60,11 +60,11 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version, room_id and sessions. pub fn new( - version: &'a str, - room_id: &'a RoomId, + version: String, + room_id: OwnedRoomId, sessions: BTreeMap>, ) -> Self { Self { version, room_id, sessions } diff --git a/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs index 78a8b309..d36b2f7e 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs @@ -12,7 +12,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; use crate::backup::KeyBackupData; @@ -30,20 +30,20 @@ pub mod v3 { /// Request type for the `add_backup_keys_for_session` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to add keys to. /// /// Must be the current backup. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room to add keys to. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the megolm session to add keys to. #[ruma_api(path)] - pub session_id: &'a str, + pub session_id: String, /// The key information to store. #[ruma_api(body)] @@ -63,12 +63,12 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version, room_id, session_id and session_data. pub fn new( - version: &'a str, - room_id: &'a RoomId, - session_id: &'a str, + version: String, + room_id: OwnedRoomId, + session_id: String, session_data: Raw, ) -> Self { Self { version, room_id, session_id, session_data } diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys.rs b/crates/ruma-client-api/src/backup/delete_backup_keys.rs index 536f1617..cadffea0 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys.rs @@ -28,10 +28,10 @@ pub mod v3 { /// Request type for the `delete_backup_keys` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version from which to delete keys. #[ruma_api(query)] - pub version: &'a str, + pub version: String, } /// Response type for the `delete_backup_keys` endpoint. @@ -47,9 +47,9 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version. - pub fn new(version: &'a str) -> Self { + pub fn new(version: String) -> Self { Self { version } } } diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs index 8bae9e91..50f6238e 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs @@ -10,7 +10,7 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -26,14 +26,14 @@ pub mod v3 { /// Request type for the `delete_backup_keys_for_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version from which to delete keys. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room to delete keys from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `delete_backup_keys_for_room` endpoint. @@ -49,10 +49,10 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version and room_id. - pub fn new(version: &'a str, room_id: &'a RoomId) -> Self { + pub fn new(version: String, room_id: OwnedRoomId) -> Self { Self { version, room_id } } } diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs index 0f9de955..2e81ddce 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs @@ -10,7 +10,7 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -26,18 +26,18 @@ pub mod v3 { /// Request type for the `delete_backup_keys_for_session` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version from which to delete keys. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room to delete keys from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the megolm session to delete keys from. #[ruma_api(path)] - pub session_id: &'a str, + pub session_id: String, } /// Response type for the `delete_backup_keys_for_session` endpoint. @@ -53,9 +53,9 @@ pub mod v3 { pub count: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version, room_id and session_id. - pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self { + pub fn new(version: String, room_id: OwnedRoomId, session_id: String) -> Self { Self { version, room_id, session_id } } } diff --git a/crates/ruma-client-api/src/backup/delete_backup_version.rs b/crates/ruma-client-api/src/backup/delete_backup_version.rs index 4b7b62ef..ee1000d8 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_version.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_version.rs @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `delete_backup_version` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to delete. #[ruma_api(path)] - pub version: &'a str, + pub version: String, } /// Response type for the `delete_backup_version` endpoint. @@ -38,9 +38,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version, room_id and sessions. - pub fn new(version: &'a str) -> Self { + pub fn new(version: String) -> Self { Self { version } } } diff --git a/crates/ruma-client-api/src/backup/get_backup_info.rs b/crates/ruma-client-api/src/backup/get_backup_info.rs index 2eb08a7b..e3168d1d 100644 --- a/crates/ruma-client-api/src/backup/get_backup_info.rs +++ b/crates/ruma-client-api/src/backup/get_backup_info.rs @@ -30,10 +30,10 @@ pub mod v3 { /// Request type for the `get_backup_info` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to retrieve info from. #[ruma_api(path)] - pub version: &'a str, + pub version: String, } /// Response type for the `get_backup_info` endpoint. @@ -56,9 +56,9 @@ pub mod v3 { pub version: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version. - pub fn new(version: &'a str) -> Self { + pub fn new(version: String) -> Self { Self { version } } } diff --git a/crates/ruma-client-api/src/backup/get_backup_keys.rs b/crates/ruma-client-api/src/backup/get_backup_keys.rs index 62098e71..5e6b0b7f 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys.rs @@ -29,10 +29,10 @@ pub mod v3 { /// Request type for the `get_backup_keys` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to retrieve keys from. #[ruma_api(query)] - pub version: &'a str, + pub version: String, } /// Response type for the `get_backup_keys` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { pub rooms: BTreeMap, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version. - pub fn new(version: &'a str) -> Self { + pub fn new(version: String) -> Self { Self { version } } } diff --git a/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs index db024403..728f6099 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs @@ -13,7 +13,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; use crate::backup::KeyBackupData; @@ -31,14 +31,14 @@ pub mod v3 { /// Request type for the `get_backup_keys_for_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to retrieve keys from. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room that the requested key is for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `get_backup_keys_for_room` endpoint. @@ -48,9 +48,9 @@ pub mod v3 { pub sessions: BTreeMap>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version and room_id. - pub fn new(version: &'a str, room_id: &'a RoomId) -> Self { + pub fn new(version: String, room_id: OwnedRoomId) -> Self { Self { version, room_id } } } diff --git a/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs index 12720f18..b1cf060e 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs @@ -11,7 +11,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; use crate::backup::KeyBackupData; @@ -29,18 +29,18 @@ pub mod v3 { /// Request type for the `get_backup_keys_for_session` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version to retrieve keys from. #[ruma_api(query)] - pub version: &'a str, + pub version: String, /// The ID of the room that the requested key is for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the megolm session whose key is requested. #[ruma_api(path)] - pub session_id: &'a str, + pub session_id: String, } /// Response type for the `get_backup_keys_for_session` endpoint. @@ -51,9 +51,9 @@ pub mod v3 { pub key_data: Raw, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given version, room_id and session_id. - pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self { + pub fn new(version: String, room_id: OwnedRoomId, session_id: String) -> Self { Self { version, room_id, session_id } } } diff --git a/crates/ruma-client-api/src/backup/update_backup_version.rs b/crates/ruma-client-api/src/backup/update_backup_version.rs index dee29e6c..27121671 100644 --- a/crates/ruma-client-api/src/backup/update_backup_version.rs +++ b/crates/ruma-client-api/src/backup/update_backup_version.rs @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `update_backup_version` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The backup version. #[ruma_api(path)] - pub version: &'a str, + pub version: String, /// The algorithm used for storing backups. #[ruma_api(body)] @@ -42,9 +42,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given backup version and algorithm. - pub fn new(version: &'a str, algorithm: Raw) -> Self { + pub fn new(version: String, algorithm: Raw) -> Self { Self { version, algorithm } } } diff --git a/crates/ruma-client-api/src/config/get_global_account_data.rs b/crates/ruma-client-api/src/config/get_global_account_data.rs index 6d0f9a83..afa6382f 100644 --- a/crates/ruma-client-api/src/config/get_global_account_data.rs +++ b/crates/ruma-client-api/src/config/get_global_account_data.rs @@ -12,7 +12,7 @@ pub mod v3 { events::AnyGlobalAccountDataEventContent, metadata, serde::Raw, - UserId, + OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -27,14 +27,14 @@ pub mod v3 { /// Request type for the `get_global_account_data` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// Type of data to retrieve. #[ruma_api(path)] - pub event_type: &'a str, + pub event_type: String, } /// Response type for the `get_global_account_data` endpoint. @@ -47,9 +47,9 @@ pub mod v3 { pub account_data: Raw, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and event type. - pub fn new(user_id: &'a UserId, event_type: &'a str) -> Self { + pub fn new(user_id: OwnedUserId, event_type: String) -> Self { Self { user_id, event_type } } } diff --git a/crates/ruma-client-api/src/config/get_room_account_data.rs b/crates/ruma-client-api/src/config/get_room_account_data.rs index 27c0abbf..38222559 100644 --- a/crates/ruma-client-api/src/config/get_room_account_data.rs +++ b/crates/ruma-client-api/src/config/get_room_account_data.rs @@ -12,7 +12,7 @@ pub mod v3 { events::AnyRoomAccountDataEventContent, metadata, serde::Raw, - RoomId, UserId, + OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -27,18 +27,18 @@ pub mod v3 { /// Request type for the `get_room_account_data` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// User ID of user for whom to retrieve data. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// Room ID for which to retrieve data. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// Type of data to retrieve. #[ruma_api(path)] - pub event_type: &'a str, + pub event_type: String, } /// Response type for the `get_room_account_data` endpoint. @@ -51,9 +51,9 @@ pub mod v3 { pub account_data: Raw, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID, room ID and event type. - pub fn new(user_id: &'a UserId, room_id: &'a RoomId, event_type: &'a str) -> Self { + pub fn new(user_id: OwnedUserId, room_id: OwnedRoomId, event_type: String) -> Self { Self { user_id, room_id, event_type } } } diff --git a/crates/ruma-client-api/src/config/set_global_account_data.rs b/crates/ruma-client-api/src/config/set_global_account_data.rs index d451cf53..587f329d 100644 --- a/crates/ruma-client-api/src/config/set_global_account_data.rs +++ b/crates/ruma-client-api/src/config/set_global_account_data.rs @@ -15,7 +15,7 @@ pub mod v3 { }, metadata, serde::Raw, - UserId, + OwnedUserId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -31,12 +31,12 @@ pub mod v3 { /// Request type for the `set_global_account_data` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the user to set account_data for. /// /// The access token must be authorized to make requests for this user ID. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The event type of the account_data to set. /// @@ -56,14 +56,14 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given data, event type and user ID. /// /// # Errors /// /// Since `Request` stores the request body in serialized form, this function can fail if /// `T`s [`Serialize`][serde::Serialize] implementation can fail. - pub fn new(user_id: &'a UserId, data: &'a T) -> serde_json::Result + pub fn new(user_id: OwnedUserId, data: &T) -> serde_json::Result where T: GlobalAccountDataEventContent, { @@ -76,7 +76,7 @@ pub mod v3 { /// Creates a new `Request` with the given raw data, event type and user ID. pub fn new_raw( - user_id: &'a UserId, + user_id: OwnedUserId, event_type: GlobalAccountDataEventType, data: Raw, ) -> Self { diff --git a/crates/ruma-client-api/src/config/set_room_account_data.rs b/crates/ruma-client-api/src/config/set_room_account_data.rs index 819a3def..586c29aa 100644 --- a/crates/ruma-client-api/src/config/set_room_account_data.rs +++ b/crates/ruma-client-api/src/config/set_room_account_data.rs @@ -14,7 +14,7 @@ pub mod v3 { }, metadata, serde::Raw, - RoomId, UserId, + OwnedRoomId, OwnedUserId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -30,16 +30,16 @@ pub mod v3 { /// Request type for the `set_room_account_data` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the user to set account_data for. /// /// The access token must be authorized to make requests for this user ID. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The ID of the room to set account_data on. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event type of the account_data to set. /// @@ -59,7 +59,7 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given data, event type, room ID and user ID. /// /// # Errors @@ -67,9 +67,9 @@ pub mod v3 { /// Since `Request` stores the request body in serialized form, this function can fail if /// `T`s [`Serialize`][serde::Serialize] implementation can fail. pub fn new( - user_id: &'a UserId, - room_id: &'a RoomId, - data: &'a T, + user_id: OwnedUserId, + room_id: OwnedRoomId, + data: &T, ) -> serde_json::Result where T: RoomAccountDataEventContent, @@ -84,8 +84,8 @@ pub mod v3 { /// Creates a new `Request` with the given raw data, event type, room ID and user ID. pub fn new_raw( - user_id: &'a UserId, - room_id: &'a RoomId, + user_id: OwnedUserId, + room_id: OwnedRoomId, event_type: RoomAccountDataEventType, data: Raw, ) -> Self { diff --git a/crates/ruma-client-api/src/context/get_context.rs b/crates/ruma-client-api/src/context/get_context.rs index 8bb4d332..ff84f16c 100644 --- a/crates/ruma-client-api/src/context/get_context.rs +++ b/crates/ruma-client-api/src/context/get_context.rs @@ -13,10 +13,10 @@ pub mod v3 { events::{AnyStateEvent, AnyTimelineEvent}, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; - use crate::filter::{IncomingRoomEventFilter, RoomEventFilter}; + use crate::filter::RoomEventFilter; const METADATA: Metadata = metadata! { method: GET, @@ -30,14 +30,14 @@ pub mod v3 { /// Request type for the `get_context` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to get events from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event to get context around. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The maximum number of events to return. /// @@ -53,7 +53,7 @@ pub mod v3 { default, skip_serializing_if = "RoomEventFilter::is_empty" )] - pub filter: RoomEventFilter<'a>, + pub filter: RoomEventFilter, } /// Response type for the `get_context` endpoint. @@ -87,9 +87,9 @@ pub mod v3 { pub state: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and event id. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self { Self { room_id, event_id, limit: default_limit(), filter: RoomEventFilter::default() } } } diff --git a/crates/ruma-client-api/src/device/delete_device.rs b/crates/ruma-client-api/src/device/delete_device.rs index 2f7242db..18e67be0 100644 --- a/crates/ruma-client-api/src/device/delete_device.rs +++ b/crates/ruma-client-api/src/device/delete_device.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, DeviceId, + metadata, OwnedDeviceId, }; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: DELETE, @@ -26,14 +26,14 @@ pub mod v3 { /// Request type for the `delete_device` endpoint. #[request(error = UiaaResponse)] - pub struct Request<'a> { + pub struct Request { /// The device to delete. #[ruma_api(path)] - pub device_id: &'a DeviceId, + pub device_id: OwnedDeviceId, /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, } /// Response type for the `delete_device` endpoint. @@ -41,9 +41,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given device ID. - pub fn new(device_id: &'a DeviceId) -> Self { + pub fn new(device_id: OwnedDeviceId) -> Self { Self { device_id, auth: None } } } diff --git a/crates/ruma-client-api/src/device/delete_devices.rs b/crates/ruma-client-api/src/device/delete_devices.rs index 44ae3df6..850e48ae 100644 --- a/crates/ruma-client-api/src/device/delete_devices.rs +++ b/crates/ruma-client-api/src/device/delete_devices.rs @@ -12,7 +12,7 @@ pub mod v3 { metadata, OwnedDeviceId, }; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: POST, @@ -26,13 +26,13 @@ pub mod v3 { /// Request type for the `delete_devices` endpoint. #[request(error = UiaaResponse)] - pub struct Request<'a> { + pub struct Request { /// List of devices to delete. - pub devices: &'a [OwnedDeviceId], + pub devices: Vec, /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, } /// Response type for the `delete_devices` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given device list. - pub fn new(devices: &'a [OwnedDeviceId]) -> Self { + pub fn new(devices: Vec) -> Self { Self { devices, auth: None } } } diff --git a/crates/ruma-client-api/src/device/get_device.rs b/crates/ruma-client-api/src/device/get_device.rs index 65611825..69ac385a 100644 --- a/crates/ruma-client-api/src/device/get_device.rs +++ b/crates/ruma-client-api/src/device/get_device.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, DeviceId, + metadata, OwnedDeviceId, }; use crate::device::Device; @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `get_device` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The device to retrieve. #[ruma_api(path)] - pub device_id: &'a DeviceId, + pub device_id: OwnedDeviceId, } /// Response type for the `get_device` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { pub device: Device, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given device ID. - pub fn new(device_id: &'a DeviceId) -> Self { + pub fn new(device_id: OwnedDeviceId) -> Self { Self { device_id } } } diff --git a/crates/ruma-client-api/src/device/update_device.rs b/crates/ruma-client-api/src/device/update_device.rs index 93631755..69b8265c 100644 --- a/crates/ruma-client-api/src/device/update_device.rs +++ b/crates/ruma-client-api/src/device/update_device.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, DeviceId, + metadata, OwnedDeviceId, }; const METADATA: Metadata = metadata! { @@ -24,16 +24,16 @@ pub mod v3 { /// Request type for the `update_device` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The device to update. #[ruma_api(path)] - pub device_id: &'a DeviceId, + pub device_id: OwnedDeviceId, /// The new display name for this device. /// /// If this is `None`, the display name won't be changed. #[serde(skip_serializing_if = "Option::is_none")] - pub display_name: Option<&'a str>, + pub display_name: Option, } /// Response type for the `update_device` endpoint. @@ -41,9 +41,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given device ID. - pub fn new(device_id: &'a DeviceId) -> Self { + pub fn new(device_id: OwnedDeviceId) -> Self { Self { device_id, display_name: None } } } diff --git a/crates/ruma-client-api/src/directory/get_public_rooms.rs b/crates/ruma-client-api/src/directory/get_public_rooms.rs index 9483e81a..c26189e7 100644 --- a/crates/ruma-client-api/src/directory/get_public_rooms.rs +++ b/crates/ruma-client-api/src/directory/get_public_rooms.rs @@ -11,7 +11,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, directory::PublicRoomsChunk, - metadata, ServerName, + metadata, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -27,7 +27,7 @@ pub mod v3 { /// Request type for the `get_public_rooms` endpoint. #[request(error = crate::Error)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] @@ -36,14 +36,14 @@ pub mod v3 { /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub since: Option<&'a str>, + pub since: Option, /// The server to fetch the public room lists from. /// /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub server: Option<&'a ServerName>, + pub server: Option, } /// Response type for the `get_public_rooms` endpoint. @@ -65,7 +65,7 @@ pub mod v3 { pub total_room_count_estimate: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() @@ -93,8 +93,8 @@ pub mod v3 { let req = super::Request { limit: Some(uint!(10)), - since: Some("hello"), - server: Some(server_name!("test.tld")), + since: Some("hello".to_owned()), + server: Some(server_name!("test.tld").to_owned()), } .try_into_http_request::>( "https://homeserver.tld", diff --git a/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs b/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs index b62c7736..65a289b9 100644 --- a/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs +++ b/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs @@ -10,8 +10,8 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, - metadata, ServerName, + directory::{Filter, PublicRoomsChunk, RoomNetwork}, + metadata, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -27,13 +27,13 @@ pub mod v3 { /// Request type for the `get_public_rooms_filtered` endpoint. #[request(error = crate::Error)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// The server to fetch the public room lists from. /// /// `None` means the server this request is sent to. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub server: Option<&'a ServerName>, + pub server: Option, /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -41,15 +41,15 @@ pub mod v3 { /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option<&'a str>, + pub since: Option, /// Filter to apply to the results. #[serde(default, skip_serializing_if = "Filter::is_empty")] - pub filter: Filter<'a>, + pub filter: Filter, /// Network to fetch the public room lists from. #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] - pub room_network: RoomNetwork<'a>, + pub room_network: RoomNetwork, } /// Response type for the `get_public_rooms_filtered` endpoint. @@ -72,7 +72,7 @@ pub mod v3 { pub total_room_count_estimate: Option, } - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/directory/get_room_visibility.rs b/crates/ruma-client-api/src/directory/get_room_visibility.rs index f6272fa8..b0120fac 100644 --- a/crates/ruma-client-api/src/directory/get_room_visibility.rs +++ b/crates/ruma-client-api/src/directory/get_room_visibility.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; use crate::room::Visibility; @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `get_room_visibility` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room of which to request the visibility. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `get_room_visibility` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { pub visibility: Visibility, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/directory/set_room_visibility.rs b/crates/ruma-client-api/src/directory/set_room_visibility.rs index fb0e3c0e..ac8431a5 100644 --- a/crates/ruma-client-api/src/directory/set_room_visibility.rs +++ b/crates/ruma-client-api/src/directory/set_room_visibility.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; use crate::room::Visibility; @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `set_room_visibility` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room of which to set the visibility. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// New visibility setting for the room. pub visibility: Visibility, @@ -40,9 +40,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and visibility. - pub fn new(room_id: &'a RoomId, visibility: Visibility) -> Self { + pub fn new(room_id: OwnedRoomId, visibility: Visibility) -> Self { Self { room_id, visibility } } } diff --git a/crates/ruma-client-api/src/filter.rs b/crates/ruma-client-api/src/filter.rs index a2d924ae..04bac57f 100644 --- a/crates/ruma-client-api/src/filter.rs +++ b/crates/ruma-client-api/src/filter.rs @@ -7,11 +7,8 @@ mod lazy_load; mod url; use js_int::UInt; -use ruma_common::{ - serde::{Incoming, StringEnum}, - OwnedRoomId, OwnedUserId, -}; -use serde::Serialize; +use ruma_common::{serde::StringEnum, OwnedRoomId, OwnedUserId}; +use serde::{Deserialize, Serialize}; use crate::PrivOwnedStr; @@ -35,24 +32,23 @@ pub enum EventFormat { } /// Filters to be applied to room events. -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Clone, Default, Serialize)] -pub struct RoomEventFilter<'a> { +pub struct RoomEventFilter { /// A list of event types to exclude. /// /// If this list is absent then no event types are excluded. A matching type will be excluded /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// sequence of characters. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_types: &'a [String], + pub not_types: Vec, /// A list of room IDs to exclude. /// /// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// it is listed in the 'rooms' filter. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_rooms: &'a [OwnedRoomId], + pub not_rooms: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -62,27 +58,27 @@ pub struct RoomEventFilter<'a> { /// /// If this list is absent then all rooms are included. #[serde(skip_serializing_if = "Option::is_none")] - pub rooms: Option<&'a [OwnedRoomId]>, + pub rooms: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded /// even if it is listed in the 'senders' filter. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_senders: &'a [OwnedUserId], + pub not_senders: Vec, /// A list of senders IDs to include. /// /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Option::is_none")] - pub senders: Option<&'a [OwnedUserId]>, + pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard /// to match any sequence of characters. #[serde(skip_serializing_if = "Option::is_none")] - pub types: Option<&'a [String]>, + pub types: Option>, /// Controls whether to include events with a URL key in their content. /// @@ -108,7 +104,7 @@ pub struct RoomEventFilter<'a> { pub unread_thread_notifications: bool, } -impl<'a> RoomEventFilter<'a> { +impl RoomEventFilter { /// Creates an empty `RoomEventFilter`. /// /// You can also use the [`Default`] implementation. @@ -118,7 +114,7 @@ impl<'a> RoomEventFilter<'a> { /// Creates a new `RoomEventFilter` that can be used to ignore all room events. pub fn ignore_all() -> Self { - Self { types: Some(&[]), ..Default::default() } + Self { types: Some(vec![]), ..Default::default() } } /// Returns `true` if all fields are empty. @@ -136,27 +132,10 @@ impl<'a> RoomEventFilter<'a> { } } -impl IncomingRoomEventFilter { - /// Returns `true` if all fields are empty. - pub fn is_empty(&self) -> bool { - self.not_types.is_empty() - && self.not_rooms.is_empty() - && self.limit.is_none() - && self.rooms.is_none() - && self.not_senders.is_empty() - && self.senders.is_none() - && self.types.is_none() - && self.url_filter.is_none() - && self.lazy_load_options.is_disabled() - && !self.unread_thread_notifications - } -} - /// Filters to be applied to room data. -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Clone, Default, Serialize)] -pub struct RoomFilter<'a> { +pub struct RoomFilter { /// Include rooms that the user has left in the sync. /// /// Defaults to `false`. @@ -165,20 +144,20 @@ pub struct RoomFilter<'a> { /// The per user account data to include for rooms. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub account_data: RoomEventFilter<'a>, + pub account_data: RoomEventFilter, /// The message and state update events to include for rooms. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub timeline: RoomEventFilter<'a>, + pub timeline: RoomEventFilter, /// The events that aren't recorded in the room history, e.g. typing and receipts, to include /// for rooms. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub ephemeral: RoomEventFilter<'a>, + pub ephemeral: RoomEventFilter, /// The state events to include for rooms. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub state: RoomEventFilter<'a>, + pub state: RoomEventFilter, /// A list of room IDs to exclude. /// @@ -186,17 +165,17 @@ pub struct RoomFilter<'a> { /// it is listed in the 'rooms' filter. This filter is applied before the filters in /// `ephemeral`, `state`, `timeline` or `account_data`. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_rooms: &'a [OwnedRoomId], + pub not_rooms: Vec, /// A list of room IDs to include. /// /// If this list is absent then all rooms are included. This filter is applied before the /// filters in `ephemeral`, `state`, `timeline` or `account_data`. #[serde(skip_serializing_if = "Option::is_none")] - pub rooms: Option<&'a [OwnedRoomId]>, + pub rooms: Option>, } -impl<'a> RoomFilter<'a> { +impl RoomFilter { /// Creates an empty `RoomFilter`. /// /// You can also use the [`Default`] implementation. @@ -206,7 +185,7 @@ impl<'a> RoomFilter<'a> { /// Creates a new `RoomFilter` that can be used to ignore all room events (of any type). pub fn ignore_all() -> Self { - Self { rooms: Some(&[]), ..Default::default() } + Self { rooms: Some(vec![]), ..Default::default() } } /// Returns `true` if all fields are empty. @@ -221,31 +200,17 @@ impl<'a> RoomFilter<'a> { } } -impl IncomingRoomFilter { - /// Returns `true` if all fields are empty. - pub fn is_empty(&self) -> bool { - !self.include_leave - && self.account_data.is_empty() - && self.timeline.is_empty() - && self.ephemeral.is_empty() - && self.state.is_empty() - && self.not_rooms.is_empty() - && self.rooms.is_none() - } -} - /// Filter for non-room data. -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Clone, Default, Serialize)] -pub struct Filter<'a> { +pub struct Filter { /// A list of event types to exclude. /// /// If this list is absent then no event types are excluded. A matching type will be excluded /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// sequence of characters. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_types: &'a [String], + pub not_types: Vec, /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -255,24 +220,24 @@ pub struct Filter<'a> { /// /// If this list is absent then all senders are included. #[serde(skip_serializing_if = "Option::is_none")] - pub senders: Option<&'a [OwnedUserId]>, + pub senders: Option>, /// A list of event types to include. /// /// If this list is absent then all event types are included. A '*' can be used as a wildcard /// to match any sequence of characters. #[serde(skip_serializing_if = "Option::is_none")] - pub types: Option<&'a [String]>, + pub types: Option>, /// A list of sender IDs to exclude. /// /// If this list is absent then no senders are excluded. A matching sender will be excluded /// even if it is listed in the 'senders' filter. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub not_senders: &'a [OwnedUserId], + pub not_senders: Vec, } -impl<'a> Filter<'a> { +impl Filter { /// Creates an empty `Filter`. /// /// You can also use the [`Default`] implementation. @@ -282,7 +247,7 @@ impl<'a> Filter<'a> { /// Creates a new `Filter` that can be used to ignore all events. pub fn ignore_all() -> Self { - Self { types: Some(&[]), ..Default::default() } + Self { types: Some(vec![]), ..Default::default() } } /// Returns `true` if all fields are empty. @@ -295,22 +260,10 @@ impl<'a> Filter<'a> { } } -impl IncomingFilter { - /// Returns `true` if all fields are empty. - pub fn is_empty(&self) -> bool { - self.not_types.is_empty() - && self.limit.is_none() - && self.senders.is_none() - && self.types.is_none() - && self.not_senders.is_empty() - } -} - /// A filter definition -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Clone, Default, Serialize)] -pub struct FilterDefinition<'a> { +pub struct FilterDefinition { /// List of event fields to include. /// /// If this list is absent then all fields are included. The entries may include '.' characters @@ -318,7 +271,7 @@ pub struct FilterDefinition<'a> { /// object. A literal '.' character in a field name may be escaped using a '\'. A server may /// include more fields than were requested. #[serde(skip_serializing_if = "Option::is_none")] - pub event_fields: Option<&'a [String]>, + pub event_fields: Option>, /// The format to use for events. /// @@ -329,18 +282,18 @@ pub struct FilterDefinition<'a> { /// The presence updates to include. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub presence: Filter<'a>, + pub presence: Filter, /// The user account data that isn't associated with rooms to include. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub account_data: Filter<'a>, + pub account_data: Filter, /// Filters to be applied to room data. #[serde(default, skip_serializing_if = "ruma_common::serde::is_empty")] - pub room: RoomFilter<'a>, + pub room: RoomFilter, } -impl<'a> FilterDefinition<'a> { +impl FilterDefinition { /// Creates an empty `FilterDefinition`. /// /// You can also use the [`Default`] implementation. @@ -368,20 +321,9 @@ impl<'a> FilterDefinition<'a> { } } -impl IncomingFilterDefinition { - /// Returns `true` if all fields are empty. - pub fn is_empty(&self) -> bool { - self.event_fields.is_none() - && self.event_format == EventFormat::Client - && self.presence.is_empty() - && self.account_data.is_empty() - && self.room.is_empty() - } -} - macro_rules! can_be_empty { - ($ty:ident $(<$gen:tt>)?) => { - impl $(<$gen>)? ruma_common::serde::CanBeEmpty for $ty $(<$gen>)? { + ($ty:ident) => { + impl ruma_common::serde::CanBeEmpty for $ty { fn is_empty(&self) -> bool { self.is_empty() } @@ -389,15 +331,10 @@ macro_rules! can_be_empty { }; } -can_be_empty!(Filter<'a>); -can_be_empty!(FilterDefinition<'a>); -can_be_empty!(RoomEventFilter<'a>); -can_be_empty!(RoomFilter<'a>); - -can_be_empty!(IncomingFilter); -can_be_empty!(IncomingFilterDefinition); -can_be_empty!(IncomingRoomEventFilter); -can_be_empty!(IncomingRoomFilter); +can_be_empty!(Filter); +can_be_empty!(FilterDefinition); +can_be_empty!(RoomEventFilter); +can_be_empty!(RoomFilter); #[cfg(test)] mod tests { @@ -405,8 +342,7 @@ mod tests { use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use super::{ - Filter, FilterDefinition, IncomingFilterDefinition, IncomingRoomEventFilter, - IncomingRoomFilter, LazyLoadOptions, RoomEventFilter, RoomFilter, UrlFilter, + Filter, FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter, UrlFilter, }; #[test] @@ -424,7 +360,7 @@ mod tests { let filter = FilterDefinition::default(); let filter_str = to_json_value(&filter)?; - let incoming_filter = from_json_value::(filter_str)?; + let incoming_filter = from_json_value::(filter_str)?; assert!(incoming_filter.is_empty()); Ok(()) @@ -435,7 +371,7 @@ mod tests { let filter = RoomFilter::default(); let room_filter = to_json_value(filter)?; - let incoming_room_filter = from_json_value::(room_filter)?; + let incoming_room_filter = from_json_value::(room_filter)?; assert!(incoming_room_filter.is_empty()); Ok(()) @@ -455,7 +391,7 @@ mod tests { "contains_url": true, }); - let filter: IncomingRoomEventFilter = assert_matches!(from_json_value(obj), Ok(f) => f); + let filter: RoomEventFilter = assert_matches!(from_json_value(obj), Ok(f) => f); assert_eq!(filter.types, Some(vec!["m.room.message".to_owned()])); assert_eq!(filter.not_types, vec![""; 0]); diff --git a/crates/ruma-client-api/src/filter/create_filter.rs b/crates/ruma-client-api/src/filter/create_filter.rs index 880fcf96..b13b528a 100644 --- a/crates/ruma-client-api/src/filter/create_filter.rs +++ b/crates/ruma-client-api/src/filter/create_filter.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, UserId, + metadata, OwnedUserId, }; - use crate::filter::{FilterDefinition, IncomingFilterDefinition}; + use crate::filter::FilterDefinition; const METADATA: Metadata = metadata! { method: POST, @@ -26,16 +26,16 @@ pub mod v3 { /// Request type for the `create_filter` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the user uploading the filter. /// /// The access token must be authorized to make requests for this user ID. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The filter definition. #[ruma_api(body)] - pub filter: FilterDefinition<'a>, + pub filter: FilterDefinition, } /// Response type for the `create_filter` endpoint. @@ -45,9 +45,9 @@ pub mod v3 { pub filter_id: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and filter definition. - pub fn new(user_id: &'a UserId, filter: FilterDefinition<'a>) -> Self { + pub fn new(user_id: OwnedUserId, filter: FilterDefinition) -> Self { Self { user_id, filter } } } @@ -66,9 +66,9 @@ pub mod v3 { fn deserialize_request() { use ruma_common::api::IncomingRequest as _; - use super::IncomingRequest; + use super::Request; - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder() .method(http::Method::POST) .uri("https://matrix.org/_matrix/client/r0/user/@foo:bar.com/filter") @@ -92,13 +92,16 @@ pub mod v3 { use crate::filter::FilterDefinition; - let req = super::Request::new(user_id!("@foo:bar.com"), FilterDefinition::default()) - .try_into_http_request::>( - "https://matrix.org", - SendAccessToken::IfRequired("tok"), - &[MatrixVersion::V1_1], - ) - .unwrap(); + let req = super::Request::new( + user_id!("@foo:bar.com").to_owned(), + FilterDefinition::default(), + ) + .try_into_http_request::>( + "https://matrix.org", + SendAccessToken::IfRequired("tok"), + &[MatrixVersion::V1_1], + ) + .unwrap(); assert_eq!(req.body(), b"{}"); } } diff --git a/crates/ruma-client-api/src/filter/get_filter.rs b/crates/ruma-client-api/src/filter/get_filter.rs index 70315712..001778d1 100644 --- a/crates/ruma-client-api/src/filter/get_filter.rs +++ b/crates/ruma-client-api/src/filter/get_filter.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, UserId, + metadata, OwnedUserId, }; - use crate::filter::IncomingFilterDefinition; + use crate::filter::FilterDefinition; const METADATA: Metadata = metadata! { method: GET, @@ -26,14 +26,14 @@ pub mod v3 { /// Request type for the `get_filter` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user ID to download a filter for. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The ID of the filter to download. #[ruma_api(path)] - pub filter_id: &'a str, + pub filter_id: String, } /// Response type for the `get_filter` endpoint. @@ -41,19 +41,19 @@ pub mod v3 { pub struct Response { /// The filter definition. #[ruma_api(body)] - pub filter: IncomingFilterDefinition, + pub filter: FilterDefinition, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and filter ID. - pub fn new(user_id: &'a UserId, filter_id: &'a str) -> Self { + pub fn new(user_id: OwnedUserId, filter_id: String) -> Self { Self { user_id, filter_id } } } impl Response { /// Creates a new `Response` with the given filter definition. - pub fn new(filter: IncomingFilterDefinition) -> Self { + pub fn new(filter: FilterDefinition) -> Self { Self { filter } } } @@ -77,9 +77,9 @@ pub mod v3 { fn serialize_response() { use ruma_common::api::OutgoingResponse; - use crate::filter::IncomingFilterDefinition; + use crate::filter::FilterDefinition; - let res = super::Response::new(IncomingFilterDefinition::default()) + let res = super::Response::new(FilterDefinition::default()) .try_into_http_response::>() .unwrap(); assert_eq!(res.body(), b"{}"); diff --git a/crates/ruma-client-api/src/keys/get_key_changes.rs b/crates/ruma-client-api/src/keys/get_key_changes.rs index 147e9085..b1b6b067 100644 --- a/crates/ruma-client-api/src/keys/get_key_changes.rs +++ b/crates/ruma-client-api/src/keys/get_key_changes.rs @@ -24,19 +24,19 @@ pub mod v3 { /// Request type for the `get_key_changes` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// 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: &'a str, + pub from: String, /// 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: &'a str, + pub to: String, } /// Response type for the `get_key_changes` endpoint. @@ -50,9 +50,9 @@ pub mod v3 { pub left: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given start and end points. - pub fn new(from: &'a str, to: &'a str) -> Self { + pub fn new(from: String, to: String) -> Self { Self { from, to } } } diff --git a/crates/ruma-client-api/src/keys/get_keys.rs b/crates/ruma-client-api/src/keys/get_keys.rs index 7e7c7f1f..b5ec144e 100644 --- a/crates/ruma-client-api/src/keys/get_keys.rs +++ b/crates/ruma-client-api/src/keys/get_keys.rs @@ -31,7 +31,7 @@ pub mod v3 { /// Request type for the `get_keys` endpoint. #[request(error = crate::Error)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// The time (in milliseconds) to wait when downloading keys from remote servers. /// /// 10 seconds is the recommended default. @@ -54,7 +54,7 @@ pub mod v3 { /// This allows the server to ensure its response contains the keys advertised by the /// notification in that sync. #[serde(skip_serializing_if = "Option::is_none")] - pub token: Option<&'a str>, + pub token: Option, } /// Response type for the `get_keys` endpoint. @@ -84,7 +84,7 @@ pub mod v3 { pub user_signing_keys: BTreeMap>, } - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/keys/upload_signing_keys.rs b/crates/ruma-client-api/src/keys/upload_signing_keys.rs index e40f302c..a4b5e304 100644 --- a/crates/ruma-client-api/src/keys/upload_signing_keys.rs +++ b/crates/ruma-client-api/src/keys/upload_signing_keys.rs @@ -14,7 +14,7 @@ pub mod v3 { serde::Raw, }; - use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; + use crate::uiaa::{AuthData, UiaaResponse}; const METADATA: Metadata = metadata! { method: POST, @@ -29,10 +29,10 @@ pub mod v3 { /// Request type for the `upload_signing_keys` endpoint. #[request(error = UiaaResponse)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Additional authentication information for the user-interactive authentication API. #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + pub auth: Option, /// The user's master key. #[serde(skip_serializing_if = "Option::is_none")] @@ -58,7 +58,7 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/knock/knock_room.rs b/crates/ruma-client-api/src/knock/knock_room.rs index 60010f9e..727b94bc 100644 --- a/crates/ruma-client-api/src/knock/knock_room.rs +++ b/crates/ruma-client-api/src/knock/knock_room.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, OwnedServerName, RoomOrAliasId, + metadata, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -24,21 +24,21 @@ pub mod v3 { /// Request type for the `knock_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room the user should knock on. #[ruma_api(path)] - pub room_id_or_alias: &'a RoomOrAliasId, + pub room_id_or_alias: OwnedRoomOrAliasId, /// The reason for joining a room. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, /// The servers to attempt to knock on the room through. /// /// One of the servers must be participating in the room. #[ruma_api(query)] #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub server_name: &'a [OwnedServerName], + pub server_name: Vec, } /// Response type for the `knock_room` endpoint. @@ -48,10 +48,10 @@ pub mod v3 { pub room_id: OwnedRoomId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID or alias. - pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self { - Self { room_id_or_alias, reason: None, server_name: &[] } + pub fn new(room_id_or_alias: OwnedRoomOrAliasId) -> Self { + Self { room_id_or_alias, reason: None, server_name: vec![] } } } diff --git a/crates/ruma-client-api/src/media/create_content.rs b/crates/ruma-client-api/src/media/create_content.rs index 5f9ecd30..981556e8 100644 --- a/crates/ruma-client-api/src/media/create_content.rs +++ b/crates/ruma-client-api/src/media/create_content.rs @@ -25,19 +25,15 @@ pub mod v3 { /// Request type for the `create_media_content` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { - /// The file contents to upload. - #[ruma_api(raw_body)] - pub file: &'a [u8], - + pub struct Request { /// The name of the file being uploaded. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub filename: Option<&'a str>, + pub filename: Option, /// The content type of the file being uploaded. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option<&'a str>, + pub content_type: Option, /// Should the server return a blurhash or not. /// @@ -51,6 +47,10 @@ pub mod v3 { rename = "xyz.amorgan.generate_blurhash" )] pub generate_blurhash: bool, + + /// The file contents to upload. + #[ruma_api(raw_body)] + pub file: Vec, } /// Response type for the `create_media_content` endpoint. @@ -72,9 +72,9 @@ pub mod v3 { pub blurhash: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given file contents. - pub fn new(file: &'a [u8]) -> Self { + pub fn new(file: Vec) -> Self { Self { file, filename: None, diff --git a/crates/ruma-client-api/src/media/create_content_async.rs b/crates/ruma-client-api/src/media/create_content_async.rs index c869a769..f4f1fa5f 100644 --- a/crates/ruma-client-api/src/media/create_content_async.rs +++ b/crates/ruma-client-api/src/media/create_content_async.rs @@ -10,7 +10,7 @@ pub mod unstable { use http::header::CONTENT_TYPE; use ruma_common::{ api::{request, response, Metadata}, - metadata, IdParseError, MxcUri, ServerName, + metadata, IdParseError, MxcUri, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -24,22 +24,22 @@ pub mod unstable { /// Request type for the `create_content_async` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] - pub server_name: &'a ServerName, + pub server_name: OwnedServerName, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] - pub media_id: &'a str, + pub media_id: String, /// The file contents to upload. #[ruma_api(raw_body)] - pub file: &'a [u8], + pub file: Vec, /// The content type of the file being uploaded. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option<&'a str>, + pub content_type: Option, // TODO: How does this and msc2448 (blurhash) interact? } @@ -47,16 +47,16 @@ pub mod unstable { #[response(error = crate::Error)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given file contents. - pub fn new(media_id: &'a str, server_name: &'a ServerName, file: &'a [u8]) -> Self { + pub fn new(media_id: String, server_name: OwnedServerName, file: Vec) -> Self { Self { media_id, server_name, file, content_type: None } } /// Creates a new `Request` with the given url and file contents. - pub fn from_url(url: &'a MxcUri, file: &'a [u8]) -> Result { + pub fn from_url(url: &MxcUri, file: Vec) -> Result { let (server_name, media_id) = url.parts()?; - Ok(Self::new(media_id, server_name, file)) + Ok(Self::new(media_id.to_owned(), server_name.to_owned(), file)) } } } diff --git a/crates/ruma-client-api/src/media/get_content.rs b/crates/ruma-client-api/src/media/get_content.rs index 68008eb4..e3e6bc1e 100644 --- a/crates/ruma-client-api/src/media/get_content.rs +++ b/crates/ruma-client-api/src/media/get_content.rs @@ -12,7 +12,7 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, IdParseError, MxcUri, ServerName, + metadata, IdParseError, MxcUri, OwnedServerName, }; use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY; @@ -29,14 +29,14 @@ pub mod v3 { /// Request type for the `get_media_content` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] - pub server_name: &'a ServerName, + pub server_name: OwnedServerName, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] - pub media_id: &'a str, + pub media_id: String, /// Whether to fetch media deemed remote. /// @@ -91,9 +91,9 @@ pub mod v3 { pub cross_origin_resource_policy: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given media ID and server name. - pub fn new(media_id: &'a str, server_name: &'a ServerName) -> Self { + pub fn new(media_id: String, server_name: OwnedServerName) -> Self { Self { media_id, server_name, @@ -104,10 +104,10 @@ pub mod v3 { } /// Creates a new `Request` with the given url. - pub fn from_url(url: &'a MxcUri) -> Result { + pub fn from_url(url: &MxcUri) -> Result { let (server_name, media_id) = url.parts()?; - Ok(Self::new(media_id, server_name)) + Ok(Self::new(media_id.to_owned(), server_name.to_owned())) } } diff --git a/crates/ruma-client-api/src/media/get_content_as_filename.rs b/crates/ruma-client-api/src/media/get_content_as_filename.rs index 4a93e9b3..d1e5a07e 100644 --- a/crates/ruma-client-api/src/media/get_content_as_filename.rs +++ b/crates/ruma-client-api/src/media/get_content_as_filename.rs @@ -10,7 +10,7 @@ pub mod v3 { use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; use ruma_common::{ api::{request, response, Metadata}, - metadata, IdParseError, MxcUri, ServerName, + metadata, IdParseError, MxcUri, OwnedServerName, }; use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY; @@ -27,18 +27,18 @@ pub mod v3 { /// Request type for the `get_media_content_as_filename` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] - pub server_name: &'a ServerName, + pub server_name: OwnedServerName, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] - pub media_id: &'a str, + pub media_id: String, /// The filename to return in the `Content-Disposition` header. #[ruma_api(path)] - pub filename: &'a str, + pub filename: String, /// Whether to fetch media deemed remote. /// @@ -80,17 +80,22 @@ pub mod v3 { pub cross_origin_resource_policy: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given media ID, server name and filename. - pub fn new(media_id: &'a str, server_name: &'a ServerName, filename: &'a str) -> Self { + pub fn new(media_id: String, server_name: OwnedServerName, filename: String) -> Self { Self { media_id, server_name, filename, allow_remote: true } } /// Creates a new `Request` with the given url and filename. - pub fn from_url(url: &'a MxcUri, filename: &'a str) -> Result { + pub fn from_url(url: &MxcUri, filename: String) -> Result { let (server_name, media_id) = url.parts()?; - Ok(Self { media_id, server_name, filename, allow_remote: true }) + Ok(Self { + media_id: media_id.to_owned(), + server_name: server_name.to_owned(), + filename, + allow_remote: true, + }) } } diff --git a/crates/ruma-client-api/src/media/get_content_thumbnail.rs b/crates/ruma-client-api/src/media/get_content_thumbnail.rs index 56dc09d6..dfa76d8b 100644 --- a/crates/ruma-client-api/src/media/get_content_thumbnail.rs +++ b/crates/ruma-client-api/src/media/get_content_thumbnail.rs @@ -13,7 +13,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, serde::StringEnum, - IdParseError, MxcUri, ServerName, + IdParseError, MxcUri, OwnedServerName, }; use crate::{http_headers::CROSS_ORIGIN_RESOURCE_POLICY, PrivOwnedStr}; @@ -30,14 +30,14 @@ pub mod v3 { /// Request type for the `get_content_thumbnail` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The server name from the mxc:// URI (the authoritory component). #[ruma_api(path)] - pub server_name: &'a ServerName, + pub server_name: OwnedServerName, /// The media ID from the mxc:// URI (the path component). #[ruma_api(path)] - pub media_id: &'a str, + pub media_id: String, /// The desired resizing method. #[ruma_api(query)] @@ -100,12 +100,12 @@ pub mod v3 { pub cross_origin_resource_policy: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given media ID, server name, desired thumbnail width /// and desired thumbnail height. pub fn new( - media_id: &'a str, - server_name: &'a ServerName, + media_id: String, + server_name: OwnedServerName, width: UInt, height: UInt, ) -> Self { @@ -123,10 +123,10 @@ pub mod v3 { /// Creates a new `Request` with the given url, desired thumbnail width and /// desired thumbnail height. - pub fn from_url(url: &'a MxcUri, width: UInt, height: UInt) -> Result { + pub fn from_url(url: &MxcUri, width: UInt, height: UInt) -> Result { let (server_name, media_id) = url.parts()?; - Ok(Self::new(media_id, server_name, width, height)) + Ok(Self::new(media_id.to_owned(), server_name.to_owned(), width, height)) } } diff --git a/crates/ruma-client-api/src/media/get_media_preview.rs b/crates/ruma-client-api/src/media/get_media_preview.rs index 9d578dd3..24af8b72 100644 --- a/crates/ruma-client-api/src/media/get_media_preview.rs +++ b/crates/ruma-client-api/src/media/get_media_preview.rs @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `get_media_preview` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// URL to get a preview of. #[ruma_api(query)] - pub url: &'a str, + pub url: String, /// Preferred point in time (in milliseconds) to return a preview for. #[ruma_api(query)] @@ -48,9 +48,9 @@ pub mod v3 { pub data: Option>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given url and timestamp. - pub fn new(url: &'a str, ts: MilliSecondsSinceUnixEpoch) -> Self { + pub fn new(url: String, ts: MilliSecondsSinceUnixEpoch) -> Self { Self { url, ts } } } diff --git a/crates/ruma-client-api/src/membership.rs b/crates/ruma-client-api/src/membership.rs index 82ce0241..3e0ec168 100644 --- a/crates/ruma-client-api/src/membership.rs +++ b/crates/ruma-client-api/src/membership.rs @@ -16,36 +16,34 @@ pub mod unban_user; use std::collections::BTreeMap; -use ruma_common::{ - serde::Incoming, thirdparty::Medium, OwnedServerName, OwnedServerSigningKeyId, UserId, -}; -use serde::Serialize; +use ruma_common::{thirdparty::Medium, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId}; +use serde::{Deserialize, Serialize}; /// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// identity which has been invited to the room. -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ThirdPartySigned<'a> { +pub struct ThirdPartySigned { /// The Matrix ID of the user who issued the invite. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The Matrix ID of the invitee. - pub mxid: &'a UserId, + pub mxid: OwnedUserId, /// The state key of the `m.third_party_invite` event. - pub token: &'a str, + pub token: String, /// A signatures object containing a signature of the entire signed object. pub signatures: BTreeMap>, } -impl<'a> ThirdPartySigned<'a> { +impl ThirdPartySigned { /// Creates a new `ThirdPartySigned` from the given sender and invitee user IDs, state key token /// and signatures. pub fn new( - sender: &'a UserId, - mxid: &'a UserId, - token: &'a str, + sender: OwnedUserId, + mxid: OwnedUserId, + token: String, signatures: BTreeMap>, ) -> Self { Self { sender, mxid, token, signatures } @@ -56,20 +54,20 @@ impl<'a> ThirdPartySigned<'a> { /// /// To create an instance of this type, first create a `Invite3pidInit` and convert it via /// `Invite3pid::from` / `.into()`. -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct Invite3pid<'a> { +pub struct Invite3pid { /// Hostname and port of identity server to be used for account lookups. - pub id_server: &'a str, + pub id_server: String, /// An access token registered with the identity server. - pub id_access_token: &'a str, + pub id_access_token: String, /// Type of third party ID. pub medium: Medium, /// Third party identifier. - pub address: &'a str, + pub address: String, } /// Initial set of fields of `Invite3pid`. @@ -78,22 +76,22 @@ pub struct Invite3pid<'a> { /// (non-breaking) release of the Matrix specification. #[derive(Debug)] #[allow(clippy::exhaustive_structs)] -pub struct Invite3pidInit<'a> { +pub struct Invite3pidInit { /// Hostname and port of identity server to be used for account lookups. - pub id_server: &'a str, + pub id_server: String, /// An access token registered with the identity server. - pub id_access_token: &'a str, + pub id_access_token: String, /// Type of third party ID. pub medium: Medium, /// Third party identifier. - pub address: &'a str, + pub address: String, } -impl<'a> From> for Invite3pid<'a> { - fn from(init: Invite3pidInit<'a>) -> Self { +impl From for Invite3pid { + fn from(init: Invite3pidInit) -> Self { let Invite3pidInit { id_server, id_access_token, medium, address } = init; Self { id_server, id_access_token, medium, address } } diff --git a/crates/ruma-client-api/src/membership/ban_user.rs b/crates/ruma-client-api/src/membership/ban_user.rs index 787d3ad2..2f9636b3 100644 --- a/crates/ruma-client-api/src/membership/ban_user.rs +++ b/crates/ruma-client-api/src/membership/ban_user.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,17 +24,17 @@ pub mod v3 { /// Request type for the `ban_user` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to kick the user from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user to ban. - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The reason for banning the user. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `ban_user` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and room id. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { Self { room_id, user_id, reason: None } } } diff --git a/crates/ruma-client-api/src/membership/forget_room.rs b/crates/ruma-client-api/src/membership/forget_room.rs index a00441ed..a474e240 100644 --- a/crates/ruma-client-api/src/membership/forget_room.rs +++ b/crates/ruma-client-api/src/membership/forget_room.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `forget_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to forget. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `forget_room` endpoint. @@ -35,9 +35,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/membership/get_member_events.rs b/crates/ruma-client-api/src/membership/get_member_events.rs index e2550519..a27b0452 100644 --- a/crates/ruma-client-api/src/membership/get_member_events.rs +++ b/crates/ruma-client-api/src/membership/get_member_events.rs @@ -12,7 +12,7 @@ pub mod v3 { events::room::member::RoomMemberEvent, metadata, serde::{Raw, StringEnum}, - RoomId, + OwnedRoomId, }; use crate::PrivOwnedStr; @@ -29,10 +29,10 @@ pub mod v3 { /// Request type for the `get_member_events` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to get the member events for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The point in time (pagination token) to return members for in the room. /// @@ -40,7 +40,7 @@ pub mod v3 { /// API. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub at: Option<&'a str>, + pub at: Option, /// The kind of memberships to filter for. /// @@ -66,9 +66,9 @@ pub mod v3 { pub chunk: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, at: None, membership: None, not_membership: None } } } @@ -106,7 +106,7 @@ pub mod v3 { mod tests { use ruma_common::api::IncomingRequest as _; - use super::{IncomingRequest, MembershipEventFilter}; + use super::{MembershipEventFilter, Request}; #[test] fn deserialization() { @@ -121,7 +121,7 @@ pub mod v3 { .build() .unwrap(); - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(), &["!dummy:example.org"], ) diff --git a/crates/ruma-client-api/src/membership/invite_user.rs b/crates/ruma-client-api/src/membership/invite_user.rs index 8966b3c5..4546425e 100644 --- a/crates/ruma-client-api/src/membership/invite_user.rs +++ b/crates/ruma-client-api/src/membership/invite_user.rs @@ -14,13 +14,11 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, - serde::Incoming, - RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; - use serde::Serialize; + use serde::{Deserialize, Serialize}; - use crate::membership::{IncomingInvite3pid, Invite3pid}; + use crate::membership::Invite3pid; const METADATA: Metadata = metadata! { method: POST, @@ -34,18 +32,18 @@ pub mod v3 { /// Request type for the `invite_user` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room where the user should be invited. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user to invite. #[serde(flatten)] - pub recipient: InvitationRecipient<'a>, + pub recipient: InvitationRecipient, /// Optional reason for inviting the user. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `invite_user` endpoint. @@ -53,9 +51,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and invitation recipient. - pub fn new(room_id: &'a RoomId, recipient: InvitationRecipient<'a>) -> Self { + pub fn new(room_id: OwnedRoomId, recipient: InvitationRecipient) -> Self { Self { room_id, recipient, reason: None } } } @@ -68,18 +66,18 @@ pub mod v3 { } /// Distinguishes between invititations by Matrix or third party identifiers. - #[derive(Clone, Debug, Incoming, Serialize)] + #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(untagged)] - pub enum InvitationRecipient<'a> { + pub enum InvitationRecipient { /// Used to invite user by their Matrix identifier. UserId { /// Matrix identifier of user. - user_id: &'a UserId, + user_id: OwnedUserId, }, /// Used to invite user by a third party identifier. - ThirdPartyId(Invite3pid<'a>), + ThirdPartyId(Invite3pid), } #[cfg(test)] @@ -88,25 +86,24 @@ pub mod v3 { use ruma_common::thirdparty::Medium; use serde_json::{from_value as from_json_value, json}; - use super::IncomingInvitationRecipient; + use super::InvitationRecipient; #[test] fn deserialize_invite_by_user_id() { - let incoming = from_json_value::( - json!({ "user_id": "@carl:example.org" }), - ) - .unwrap(); + let incoming = + from_json_value::(json!({ "user_id": "@carl:example.org" })) + .unwrap(); let user_id = assert_matches!( incoming, - IncomingInvitationRecipient::UserId { user_id } => user_id + InvitationRecipient::UserId { user_id } => user_id ); assert_eq!(user_id, "@carl:example.org"); } #[test] fn deserialize_invite_by_3pid() { - let incoming = from_json_value::(json!({ + let incoming = from_json_value::(json!({ "id_server": "example.org", "id_access_token": "abcdefghijklmnop", "medium": "email", @@ -116,7 +113,7 @@ pub mod v3 { let third_party_id = assert_matches!( incoming, - IncomingInvitationRecipient::ThirdPartyId(id) => id + InvitationRecipient::ThirdPartyId(id) => id ); assert_eq!(third_party_id.id_server, "example.org"); diff --git a/crates/ruma-client-api/src/membership/join_room_by_id.rs b/crates/ruma-client-api/src/membership/join_room_by_id.rs index e577f0aa..dcab9402 100644 --- a/crates/ruma-client-api/src/membership/join_room_by_id.rs +++ b/crates/ruma-client-api/src/membership/join_room_by_id.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, RoomId, + metadata, OwnedRoomId, }; - use crate::membership::{IncomingThirdPartySigned, ThirdPartySigned}; + use crate::membership::ThirdPartySigned; const METADATA: Metadata = metadata! { method: POST, @@ -26,19 +26,19 @@ pub mod v3 { /// Request type for the `join_room_by_id` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room where the user should be invited. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option>, + pub third_party_signed: Option, /// Optional reason for joining the room. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `join_room_by_id` endpoint. @@ -48,9 +48,9 @@ pub mod v3 { pub room_id: OwnedRoomId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, third_party_signed: None, reason: None } } } diff --git a/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs b/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs index 07ec82a3..72afc9b7 100644 --- a/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs +++ b/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs @@ -9,10 +9,10 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, OwnedServerName, RoomOrAliasId, + metadata, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, }; - use crate::membership::{IncomingThirdPartySigned, ThirdPartySigned}; + use crate::membership::ThirdPartySigned; const METADATA: Metadata = metadata! { method: POST, @@ -26,26 +26,26 @@ pub mod v3 { /// Request type for the `join_room_by_id_or_alias` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room where the user should be invited. #[ruma_api(path)] - pub room_id_or_alias: &'a RoomOrAliasId, + pub room_id_or_alias: OwnedRoomOrAliasId, /// The servers to attempt to join the room through. /// /// One of the servers must be participating in the room. #[ruma_api(query)] #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub server_name: &'a [OwnedServerName], + pub server_name: Vec, /// The signature of a `m.third_party_invite` token to prove that this user owns a third /// party identity which has been invited to the room. #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option>, + pub third_party_signed: Option, /// Optional reason for joining the room. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `join_room_by_id_or_alias` endpoint. @@ -55,10 +55,10 @@ pub mod v3 { pub room_id: OwnedRoomId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID or alias ID. - pub fn new(room_id_or_alias: &'a RoomOrAliasId) -> Self { - Self { room_id_or_alias, server_name: &[], third_party_signed: None, reason: None } + pub fn new(room_id_or_alias: OwnedRoomOrAliasId) -> Self { + Self { room_id_or_alias, server_name: vec![], third_party_signed: None, reason: None } } } diff --git a/crates/ruma-client-api/src/membership/joined_members.rs b/crates/ruma-client-api/src/membership/joined_members.rs index 807d9a0e..3f0ffafc 100644 --- a/crates/ruma-client-api/src/membership/joined_members.rs +++ b/crates/ruma-client-api/src/membership/joined_members.rs @@ -12,7 +12,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedMxcUri, OwnedUserId, RoomId, + metadata, OwnedMxcUri, OwnedRoomId, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -28,10 +28,10 @@ pub mod v3 { /// Request type for the `joined_members` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to get the members of. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `joined_members` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { pub joined: BTreeMap, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/membership/kick_user.rs b/crates/ruma-client-api/src/membership/kick_user.rs index fb50c0d2..c4292b9b 100644 --- a/crates/ruma-client-api/src/membership/kick_user.rs +++ b/crates/ruma-client-api/src/membership/kick_user.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,17 +24,17 @@ pub mod v3 { /// Request type for the `kick_user` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to kick the user from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user to kick. - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The reason for kicking the user. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `kick_user` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and room id. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { Self { room_id, user_id, reason: None } } } diff --git a/crates/ruma-client-api/src/membership/leave_room.rs b/crates/ruma-client-api/src/membership/leave_room.rs index e5d936ec..85f9a3dc 100644 --- a/crates/ruma-client-api/src/membership/leave_room.rs +++ b/crates/ruma-client-api/src/membership/leave_room.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -24,14 +24,14 @@ pub mod v3 { /// Request type for the `leave_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to leave. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// Optional reason to be included as the `reason` on the subsequent membership event. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `leave_room` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, reason: None } } } diff --git a/crates/ruma-client-api/src/membership/mutual_rooms.rs b/crates/ruma-client-api/src/membership/mutual_rooms.rs index adf43588..f13737c2 100644 --- a/crates/ruma-client-api/src/membership/mutual_rooms.rs +++ b/crates/ruma-client-api/src/membership/mutual_rooms.rs @@ -9,7 +9,7 @@ pub mod unstable { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -23,10 +23,10 @@ pub mod unstable { /// Request type for the `mutual_rooms` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user to search mutual rooms for. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `mutual_rooms` endpoint. @@ -36,9 +36,9 @@ pub mod unstable { pub joined: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/membership/unban_user.rs b/crates/ruma-client-api/src/membership/unban_user.rs index e5ab7fd2..26c63dab 100644 --- a/crates/ruma-client-api/src/membership/unban_user.rs +++ b/crates/ruma-client-api/src/membership/unban_user.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,17 +24,17 @@ pub mod v3 { /// Request type for the `unban_user` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to unban the user from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user to unban. - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// Optional reason for unbanning the user. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `unban_user` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and room id. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { Self { room_id, user_id, reason: None } } } diff --git a/crates/ruma-client-api/src/message/get_message_events.rs b/crates/ruma-client-api/src/message/get_message_events.rs index 33e2ae49..e4b5d3c6 100644 --- a/crates/ruma-client-api/src/message/get_message_events.rs +++ b/crates/ruma-client-api/src/message/get_message_events.rs @@ -13,13 +13,10 @@ pub mod v3 { events::{AnyStateEvent, AnyTimelineEvent}, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; - use crate::{ - filter::{IncomingRoomEventFilter, RoomEventFilter}, - Direction, - }; + use crate::{filter::RoomEventFilter, Direction}; const METADATA: Metadata = metadata! { method: GET, @@ -33,10 +30,10 @@ pub mod v3 { /// Request type for the `get_message_events` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to get events from. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The token to start returning events from. /// @@ -47,7 +44,7 @@ pub mod v3 { /// If this is `None`, the server will return messages from the start or end of the /// history visible to the user, depending on the value of [`dir`][Self::dir]. #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// The token to stop returning events at. /// @@ -56,7 +53,7 @@ pub mod v3 { /// this endpoint. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub to: Option<&'a str>, + pub to: Option, /// The direction to return events from. #[ruma_api(query)] @@ -76,7 +73,7 @@ pub mod v3 { default, skip_serializing_if = "RoomEventFilter::is_empty" )] - pub filter: RoomEventFilter<'a>, + pub filter: RoomEventFilter, } /// Response type for the `get_message_events` endpoint. @@ -99,11 +96,11 @@ pub mod v3 { pub state: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and direction. /// /// All other parameters will be defaulted. - pub fn new(room_id: &'a RoomId, dir: Direction) -> Self { + pub fn new(room_id: OwnedRoomId, dir: Direction) -> Self { Self { room_id, from: None, @@ -123,11 +120,11 @@ pub mod v3 { /// /// ```rust /// # use ruma_client_api::message::get_message_events; - /// # let room_id = ruma_common::room_id!("!a:example.org"); - /// # let token = "prev_batch token"; + /// # let room_id = ruma_common::room_id!("!a:example.org").to_owned(); + /// # let token = "prev_batch token".to_owned(); /// let request = get_message_events::v3::Request::backward(room_id).from(token); /// ``` - pub fn backward(room_id: &'a RoomId) -> Self { + pub fn backward(room_id: OwnedRoomId) -> Self { Self::new(room_id, Direction::Backward) } @@ -140,11 +137,11 @@ pub mod v3 { /// /// ```rust /// # use ruma_client_api::message::get_message_events; - /// # let room_id = ruma_common::room_id!("!a:example.org"); - /// # let token = "end token"; + /// # let room_id = ruma_common::room_id!("!a:example.org").to_owned(); + /// # let token = "end token".to_owned(); /// let request = get_message_events::v3::Request::forward(room_id).from(token); /// ``` - pub fn forward(room_id: &'a RoomId) -> Self { + pub fn forward(room_id: OwnedRoomId) -> Self { Self::new(room_id, Direction::Forward) } @@ -152,7 +149,7 @@ pub mod v3 { /// /// Since the field is public, you can also assign to it directly. This method merely acts /// as a shorthand for that, because it is very common to set this field. - pub fn from(self, from: impl Into>) -> Self { + pub fn from(self, from: impl Into>) -> Self { Self { from: from.into(), ..self } } } @@ -189,23 +186,23 @@ pub mod v3 { #[test] fn serialize_some_room_event_filter() { - let room_id = room_id!("!roomid:example.org"); - let rooms = &[room_id.to_owned()]; + let room_id = room_id!("!roomid:example.org").to_owned(); + let rooms = vec![room_id.to_owned()]; let filter = RoomEventFilter { lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: true }, rooms: Some(rooms), - not_rooms: &[ + not_rooms: vec![ room_id!("!room:example.org").to_owned(), room_id!("!room2:example.org").to_owned(), room_id!("!room3:example.org").to_owned(), ], - not_types: &["type".into()], + not_types: vec!["type".into()], ..Default::default() }; let req = Request { room_id, - from: Some("token"), - to: Some("token2"), + from: Some("token".to_owned()), + to: Some("token2".to_owned()), dir: Direction::Backward, limit: uint!(0), filter, @@ -230,11 +227,11 @@ pub mod v3 { #[test] fn serialize_default_room_event_filter() { - let room_id = room_id!("!roomid:example.org"); + let room_id = room_id!("!roomid:example.org").to_owned(); let req = Request { room_id, - from: Some("token"), - to: Some("token2"), + from: Some("token".to_owned()), + to: Some("token2".to_owned()), dir: Direction::Backward, limit: uint!(0), filter: RoomEventFilter::default(), diff --git a/crates/ruma-client-api/src/message/send_message_event.rs b/crates/ruma-client-api/src/message/send_message_event.rs index b127c03b..1000779c 100644 --- a/crates/ruma-client-api/src/message/send_message_event.rs +++ b/crates/ruma-client-api/src/message/send_message_event.rs @@ -12,7 +12,7 @@ pub mod v3 { events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType}, metadata, serde::Raw, - MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, TransactionId, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -28,10 +28,10 @@ pub mod v3 { /// Request type for the `create_message_event` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to send the event to. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The type of event to send. #[ruma_api(path)] @@ -47,7 +47,7 @@ pub mod v3 { /// /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens #[ruma_api(path)] - pub txn_id: &'a TransactionId, + pub txn_id: OwnedTransactionId, /// The event content to send. #[ruma_api(body)] @@ -72,7 +72,7 @@ pub mod v3 { pub event_id: OwnedEventId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id, transaction id and event content. /// /// # Errors @@ -80,9 +80,9 @@ pub mod v3 { /// Since `Request` stores the request body in serialized form, this function can fail if /// `T`s [`Serialize`][serde::Serialize] implementation can fail. pub fn new( - room_id: &'a RoomId, - txn_id: &'a TransactionId, - content: &'a T, + room_id: OwnedRoomId, + txn_id: OwnedTransactionId, + content: &T, ) -> serde_json::Result where T: MessageLikeEventContent, @@ -99,8 +99,8 @@ pub mod v3 { /// Creates a new `Request` with the given room id, transaction id, event type and raw event /// content. pub fn new_raw( - room_id: &'a RoomId, - txn_id: &'a TransactionId, + room_id: OwnedRoomId, + txn_id: OwnedTransactionId, event_type: MessageLikeEventType, body: Raw, ) -> Self { diff --git a/crates/ruma-client-api/src/presence/get_presence.rs b/crates/ruma-client-api/src/presence/get_presence.rs index b8eb60a1..f64717b8 100644 --- a/crates/ruma-client-api/src/presence/get_presence.rs +++ b/crates/ruma-client-api/src/presence/get_presence.rs @@ -13,7 +13,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, presence::PresenceState, - UserId, + OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -28,10 +28,10 @@ pub mod v3 { /// Request type for the `get_presence` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose presence state will be retrieved. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_presence` endpoint. @@ -57,9 +57,9 @@ pub mod v3 { pub presence: PresenceState, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/presence/set_presence.rs b/crates/ruma-client-api/src/presence/set_presence.rs index b264c9b5..ac28fb48 100644 --- a/crates/ruma-client-api/src/presence/set_presence.rs +++ b/crates/ruma-client-api/src/presence/set_presence.rs @@ -11,7 +11,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, presence::PresenceState, - UserId, + OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -26,17 +26,17 @@ pub mod v3 { /// Request type for the `set_presence` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose presence state will be updated. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The new presence state. pub presence: PresenceState, /// The status message to attach to this state. #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option<&'a str>, + pub status_msg: Option, } /// Response type for the `set_presence` endpoint. @@ -44,9 +44,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and presence state. - pub fn new(user_id: &'a UserId, presence: PresenceState) -> Self { + pub fn new(user_id: OwnedUserId, presence: PresenceState) -> Self { Self { user_id, presence, status_msg: None } } } diff --git a/crates/ruma-client-api/src/profile/get_avatar_url.rs b/crates/ruma-client-api/src/profile/get_avatar_url.rs index d699aabf..59d8d09b 100644 --- a/crates/ruma-client-api/src/profile/get_avatar_url.rs +++ b/crates/ruma-client-api/src/profile/get_avatar_url.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedMxcUri, UserId, + metadata, OwnedMxcUri, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `get_avatar_url` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose avatar URL will be retrieved. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_avatar_url` endpoint. @@ -54,9 +54,9 @@ pub mod v3 { pub blurhash: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/profile/get_display_name.rs b/crates/ruma-client-api/src/profile/get_display_name.rs index b282c8d2..d3f56984 100644 --- a/crates/ruma-client-api/src/profile/get_display_name.rs +++ b/crates/ruma-client-api/src/profile/get_display_name.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, UserId, + metadata, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `get_display_name` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose display name will be retrieved. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_display_name` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { pub displayname: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/profile/get_profile.rs b/crates/ruma-client-api/src/profile/get_profile.rs index a9db38b6..c08d832d 100644 --- a/crates/ruma-client-api/src/profile/get_profile.rs +++ b/crates/ruma-client-api/src/profile/get_profile.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedMxcUri, UserId, + metadata, OwnedMxcUri, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `get_profile` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose profile will be retrieved. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_profile` endpoint. @@ -58,9 +58,9 @@ pub mod v3 { pub blurhash: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/profile/set_avatar_url.rs b/crates/ruma-client-api/src/profile/set_avatar_url.rs index 6343a335..6442b4b4 100644 --- a/crates/ruma-client-api/src/profile/set_avatar_url.rs +++ b/crates/ruma-client-api/src/profile/set_avatar_url.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, MxcUri, UserId, + metadata, OwnedMxcUri, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,10 +24,10 @@ pub mod v3 { /// Request type for the `set_avatar_url` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose avatar URL will be set. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The new avatar URL for the user. /// @@ -44,7 +44,7 @@ pub mod v3 { ) )] #[cfg_attr(not(feature = "compat"), serde(skip_serializing_if = "Option::is_none"))] - pub avatar_url: Option<&'a MxcUri>, + pub avatar_url: Option, /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. /// @@ -52,7 +52,7 @@ pub mod v3 { /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). #[cfg(feature = "unstable-msc2448")] #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option<&'a str>, + pub blurhash: Option, } /// Response type for the `set_avatar_url` endpoint. @@ -60,9 +60,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and avatar URL. - pub fn new(user_id: &'a UserId, avatar_url: Option<&'a MxcUri>) -> Self { + pub fn new(user_id: OwnedUserId, avatar_url: Option) -> Self { Self { user_id, avatar_url, @@ -83,11 +83,11 @@ pub mod v3 { mod tests { use ruma_common::api::IncomingRequest as _; - use super::IncomingRequest; + use super::Request; #[test] fn deserialize_unset_request() { - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder() .method("PUT") .uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url") @@ -101,7 +101,7 @@ pub mod v3 { #[cfg(feature = "compat")] { - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder() .method("PUT") .uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url") diff --git a/crates/ruma-client-api/src/profile/set_display_name.rs b/crates/ruma-client-api/src/profile/set_display_name.rs index c506fc5d..fb2bcb2c 100644 --- a/crates/ruma-client-api/src/profile/set_display_name.rs +++ b/crates/ruma-client-api/src/profile/set_display_name.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, UserId, + metadata, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,14 +24,14 @@ pub mod v3 { /// Request type for the `set_display_name` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose display name will be set. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The new display name for the user. #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option<&'a str>, + pub displayname: Option, } /// Response type for the `set_display_name` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and display name. - pub fn new(user_id: &'a UserId, displayname: Option<&'a str>) -> Self { + pub fn new(user_id: OwnedUserId, displayname: Option) -> Self { Self { user_id, displayname } } } diff --git a/crates/ruma-client-api/src/push/delete_pushrule.rs b/crates/ruma-client-api/src/push/delete_pushrule.rs index a53a384a..c326b12f 100644 --- a/crates/ruma-client-api/src/push/delete_pushrule.rs +++ b/crates/ruma-client-api/src/push/delete_pushrule.rs @@ -26,7 +26,7 @@ pub mod v3 { /// Request type for the `delete_pushrule` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to delete from. #[ruma_api(path)] pub scope: RuleScope, @@ -37,7 +37,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, } /// Response type for the `delete_pushrule` endpoint. @@ -45,9 +45,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, kind and rule ID. - pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn new(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self { scope, kind, rule_id } } } diff --git a/crates/ruma-client-api/src/push/get_notifications.rs b/crates/ruma-client-api/src/push/get_notifications.rs index d7aa58e9..ef1e2752 100644 --- a/crates/ruma-client-api/src/push/get_notifications.rs +++ b/crates/ruma-client-api/src/push/get_notifications.rs @@ -31,11 +31,11 @@ pub mod v3 { /// Request type for the `get_notifications` endpoint. #[request(error = crate::Error)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Pagination token given to retrieve the next set of events. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub from: Option<&'a str>, + pub from: Option, /// Limit on the number of events to return in this request. #[ruma_api(query)] @@ -48,7 +48,7 @@ pub mod v3 { /// tweak set. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub only: Option<&'a str>, + pub only: Option, } /// Response type for the `get_notifications` endpoint. @@ -65,7 +65,7 @@ pub mod v3 { pub notifications: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/push/get_pushrule.rs b/crates/ruma-client-api/src/push/get_pushrule.rs index 3027cf4f..66b386b7 100644 --- a/crates/ruma-client-api/src/push/get_pushrule.rs +++ b/crates/ruma-client-api/src/push/get_pushrule.rs @@ -26,7 +26,7 @@ pub mod v3 { /// Request type for the `get_pushrule` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to fetch rules from. #[ruma_api(path)] pub scope: RuleScope, @@ -37,7 +37,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, } /// Response type for the `get_pushrule` endpoint. @@ -48,9 +48,9 @@ pub mod v3 { pub rule: PushRule, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, rule kind and rule ID. - pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn new(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self { scope, kind, rule_id } } } diff --git a/crates/ruma-client-api/src/push/get_pushrule_actions.rs b/crates/ruma-client-api/src/push/get_pushrule_actions.rs index 375039f8..9b510e06 100644 --- a/crates/ruma-client-api/src/push/get_pushrule_actions.rs +++ b/crates/ruma-client-api/src/push/get_pushrule_actions.rs @@ -27,7 +27,7 @@ pub mod v3 { /// Request type for the `get_pushrule_actions` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to fetch a rule from. #[ruma_api(path)] pub scope: RuleScope, @@ -38,7 +38,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, } /// Response type for the `get_pushrule_actions` endpoint. @@ -48,9 +48,9 @@ pub mod v3 { pub actions: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, kind and rule ID. - pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn new(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self { scope, kind, rule_id } } } diff --git a/crates/ruma-client-api/src/push/get_pushrule_enabled.rs b/crates/ruma-client-api/src/push/get_pushrule_enabled.rs index 134c97d8..d21c906a 100644 --- a/crates/ruma-client-api/src/push/get_pushrule_enabled.rs +++ b/crates/ruma-client-api/src/push/get_pushrule_enabled.rs @@ -26,7 +26,7 @@ pub mod v3 { /// Request type for the `get_pushrule_enabled` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to fetch a rule from. #[ruma_api(path)] pub scope: RuleScope, @@ -37,7 +37,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, } /// Response type for the `get_pushrule_enabled` endpoint. @@ -47,9 +47,9 @@ pub mod v3 { pub enabled: bool, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, rule kind and rule ID. - pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn new(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self { scope, kind, rule_id } } } diff --git a/crates/ruma-client-api/src/push/set_pushrule.rs b/crates/ruma-client-api/src/push/set_pushrule.rs index 9be64360..82a288fc 100644 --- a/crates/ruma-client-api/src/push/set_pushrule.rs +++ b/crates/ruma-client-api/src/push/set_pushrule.rs @@ -11,7 +11,6 @@ pub mod v3 { api::{response, Metadata}, metadata, push::{Action, NewPushRule, PushCondition}, - serde::Incoming, }; use serde::{Deserialize, Serialize}; @@ -28,10 +27,9 @@ pub mod v3 { }; /// Request type for the `set_pushrule` endpoint. - #[derive(Clone, Debug, Incoming)] + #[derive(Clone, Debug)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize)] - pub struct Request<'a> { + pub struct Request { /// The scope to set the rule in. pub scope: RuleScope, @@ -40,11 +38,11 @@ pub mod v3 { /// Use 'before' with a rule_id as its value to make the new rule the next-most important /// rule with respect to the given user defined rule. - pub before: Option<&'a str>, + pub before: Option, /// This makes the new rule the next-less important rule relative to the given user defined /// rule. - pub after: Option<&'a str>, + pub after: Option, } /// Response type for the `set_pushrule` endpoint. @@ -52,7 +50,7 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope and rule. pub fn new(scope: RuleScope, rule: NewPushRule) -> Self { Self { scope, rule, before: None, after: None } @@ -67,7 +65,7 @@ pub mod v3 { } #[cfg(feature = "client")] - impl<'a> ruma_common::api::OutgoingRequest for Request<'a> { + impl ruma_common::api::OutgoingRequest for Request { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -113,7 +111,7 @@ pub mod v3 { } #[cfg(feature = "server")] - impl ruma_common::api::IncomingRequest for IncomingRequest { + impl ruma_common::api::IncomingRequest for Request { type EndpointError = crate::Error; type OutgoingResponse = Response; @@ -196,12 +194,12 @@ pub mod v3 { } #[derive(Debug, Serialize)] - struct RequestQuery<'a> { + struct RequestQuery { #[serde(skip_serializing_if = "Option::is_none")] - before: Option<&'a str>, + before: Option, #[serde(skip_serializing_if = "Option::is_none")] - after: Option<&'a str>, + after: Option, } #[derive(Debug, Serialize)] diff --git a/crates/ruma-client-api/src/push/set_pushrule_actions.rs b/crates/ruma-client-api/src/push/set_pushrule_actions.rs index 371c7cc7..a36556ea 100644 --- a/crates/ruma-client-api/src/push/set_pushrule_actions.rs +++ b/crates/ruma-client-api/src/push/set_pushrule_actions.rs @@ -28,7 +28,7 @@ pub mod v3 { /// Request type for the `set_pushrule_actions` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to fetch a rule from. #[ruma_api(path)] pub scope: RuleScope, @@ -39,7 +39,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, /// The actions to perform for this rule pub actions: Vec, @@ -50,12 +50,12 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, rule kind, rule ID and actions. pub fn new( scope: RuleScope, kind: RuleKind, - rule_id: &'a str, + rule_id: String, actions: Vec, ) -> Self { Self { scope, kind, rule_id, actions } diff --git a/crates/ruma-client-api/src/push/set_pushrule_enabled.rs b/crates/ruma-client-api/src/push/set_pushrule_enabled.rs index 275b0a4a..e840cd7c 100644 --- a/crates/ruma-client-api/src/push/set_pushrule_enabled.rs +++ b/crates/ruma-client-api/src/push/set_pushrule_enabled.rs @@ -26,7 +26,7 @@ pub mod v3 { /// Request type for the `set_pushrule_enabled` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The scope to fetch a rule from. #[ruma_api(path)] pub scope: RuleScope, @@ -37,7 +37,7 @@ pub mod v3 { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: &'a str, + pub rule_id: String, /// Whether the push rule is enabled or not. pub enabled: bool, @@ -48,19 +48,19 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given scope, rule kind, rule ID and enabled flag. - pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str, enabled: bool) -> Self { + pub fn new(scope: RuleScope, kind: RuleKind, rule_id: String, enabled: bool) -> Self { Self { scope, kind, rule_id, enabled } } /// Creates a new `Request` to enable the given rule. - pub fn enable(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn enable(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self::new(scope, kind, rule_id, true) } /// Creates a new `Request` to disable the given rule. - pub fn disable(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { + pub fn disable(scope: RuleScope, kind: RuleKind, rule_id: String) -> Self { Self::new(scope, kind, rule_id, false) } } diff --git a/crates/ruma-client-api/src/read_marker/set_read_marker.rs b/crates/ruma-client-api/src/read_marker/set_read_marker.rs index 00a12d05..2419e3e8 100644 --- a/crates/ruma-client-api/src/read_marker/set_read_marker.rs +++ b/crates/ruma-client-api/src/read_marker/set_read_marker.rs @@ -14,7 +14,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -29,10 +29,10 @@ pub mod v3 { /// Request type for the `set_read_marker` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room ID to set the read marker in for the user. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID the fully-read marker should be located at. /// @@ -44,7 +44,7 @@ pub mod v3 { /// [`create_receipt`]: crate::receipt::create_receipt /// [`ReceiptType::FullyRead`]: crate::receipt::create_receipt::v3::ReceiptType::FullyRead #[serde(rename = "m.fully_read", skip_serializing_if = "Option::is_none")] - pub fully_read: Option<&'a EventId>, + pub fully_read: Option, /// The event ID to set the public read receipt location at. /// @@ -54,7 +54,7 @@ pub mod v3 { /// [`create_receipt`]: crate::receipt::create_receipt /// [`ReceiptType::Read`]: crate::receipt::create_receipt::v3::ReceiptType::Read #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")] - pub read_receipt: Option<&'a EventId>, + pub read_receipt: Option, /// The event ID to set the private read receipt location at. /// @@ -64,7 +64,7 @@ pub mod v3 { /// [`create_receipt`]: crate::receipt::create_receipt /// [`ReceiptType::ReadPrivate`]: crate::receipt::create_receipt::v3::ReceiptType::ReadPrivate #[serde(rename = "m.read.private", skip_serializing_if = "Option::is_none")] - pub private_read_receipt: Option<&'a EventId>, + pub private_read_receipt: Option, } /// Response type for the `set_read_marker` endpoint. @@ -72,9 +72,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, fully_read: None, read_receipt: None, private_read_receipt: None } } } diff --git a/crates/ruma-client-api/src/receipt/create_receipt.rs b/crates/ruma-client-api/src/receipt/create_receipt.rs index 4346bef8..eda5a392 100644 --- a/crates/ruma-client-api/src/receipt/create_receipt.rs +++ b/crates/ruma-client-api/src/receipt/create_receipt.rs @@ -12,7 +12,7 @@ pub mod v3 { events::receipt::ReceiptThread, metadata, serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum}, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; use crate::PrivOwnedStr; @@ -29,10 +29,10 @@ pub mod v3 { /// Request type for the `create_receipt` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room in which to send the event. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The type of receipt to send. #[ruma_api(path)] @@ -40,7 +40,7 @@ pub mod v3 { /// The event ID to acknowledge up to. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The thread this receipt applies to. /// @@ -61,9 +61,13 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, receipt type and event ID. - pub fn new(room_id: &'a RoomId, receipt_type: ReceiptType, event_id: &'a EventId) -> Self { + pub fn new( + room_id: OwnedRoomId, + receipt_type: ReceiptType, + event_id: OwnedEventId, + ) -> Self { Self { room_id, receipt_type, event_id, thread: ReceiptThread::default() } } } diff --git a/crates/ruma-client-api/src/redact/redact_event.rs b/crates/ruma-client-api/src/redact/redact_event.rs index ccb0e8ab..864538bc 100644 --- a/crates/ruma-client-api/src/redact/redact_event.rs +++ b/crates/ruma-client-api/src/redact/redact_event.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, OwnedEventId, RoomId, TransactionId, + metadata, OwnedEventId, OwnedRoomId, OwnedTransactionId, }; const METADATA: Metadata = metadata! { @@ -24,14 +24,14 @@ pub mod v3 { /// Request type for the `redact_event` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room of the event to redact. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the event to redact. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The transaction ID for this event. /// @@ -43,11 +43,11 @@ pub mod v3 { /// /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens #[ruma_api(path)] - pub txn_id: &'a TransactionId, + pub txn_id: OwnedTransactionId, /// The reason for the redaction. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `redact_event` endpoint. @@ -57,9 +57,13 @@ pub mod v3 { pub event_id: OwnedEventId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, event ID and transaction ID. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, txn_id: &'a TransactionId) -> Self { + pub fn new( + room_id: OwnedRoomId, + event_id: OwnedEventId, + txn_id: OwnedTransactionId, + ) -> Self { Self { room_id, event_id, txn_id, reason: None } } } diff --git a/crates/ruma-client-api/src/relations/get_relating_events.rs b/crates/ruma-client-api/src/relations/get_relating_events.rs index 6bc8da59..61a22853 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events.rs @@ -13,7 +13,7 @@ pub mod v1 { events::AnyMessageLikeEvent, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; use crate::Direction; @@ -30,14 +30,14 @@ pub mod v1 { /// Request type for the `get_relating_events` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room containing the parent event. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the parent event whose child events are to be returned. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The pagination token to start returning results from. /// @@ -51,7 +51,7 @@ pub mod v1 { /// through events, starting at `from`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// The direction to return events from. /// @@ -68,7 +68,7 @@ pub mod v1 { /// or from `/messages` or `/sync`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub to: Option<&'a str>, + pub to: Option, /// The maximum number of results to return in a single `chunk`. /// @@ -107,9 +107,9 @@ pub mod v1 { pub prev_batch: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and parent event ID. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self { Self { room_id, event_id, dir: Direction::default(), from: None, to: None, limit: None } } } diff --git a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs index cb180c28..e35f7e97 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs @@ -14,7 +14,7 @@ pub mod v1 { events::{relation::RelationType, AnyMessageLikeEvent}, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -29,14 +29,14 @@ pub mod v1 { /// Request type for the `get_relating_events_with_rel_type` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room containing the parent event. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the parent event whose child events are to be returned. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The relationship type to search for. #[ruma_api(path)] @@ -54,7 +54,7 @@ pub mod v1 { /// through events, starting at `from`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// The pagination token to stop returning results at. /// @@ -64,7 +64,7 @@ pub mod v1 { /// or from `/messages` or `/sync`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub to: Option<&'a str>, + pub to: Option, /// The maximum number of results to return in a single `chunk`. /// @@ -104,9 +104,9 @@ pub mod v1 { pub prev_batch: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, parent event ID and relationship type. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, rel_type: RelationType) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, rel_type: RelationType) -> Self { Self { room_id, event_id, rel_type, from: None, to: None, limit: None } } } diff --git a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs index 15389190..31c5fab2 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs @@ -14,7 +14,7 @@ pub mod v1 { events::{relation::RelationType, AnyMessageLikeEvent, RoomEventType}, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -29,14 +29,14 @@ pub mod v1 { /// Request type for the `get_relating_events_with_rel_type_and_event_type` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room containing the parent event. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the parent event whose child events are to be returned. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The relationship type to search for. #[ruma_api(path)] @@ -61,7 +61,7 @@ pub mod v1 { /// through events, starting at `from`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// The pagination token to stop returning results at. /// @@ -71,7 +71,7 @@ pub mod v1 { /// or from `/messages` or `/sync`. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub to: Option<&'a str>, + pub to: Option, /// The maximum number of results to return in a single `chunk`. /// @@ -111,12 +111,12 @@ pub mod v1 { pub prev_batch: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, parent event ID, relationship type and /// event type. pub fn new( - room_id: &'a RoomId, - event_id: &'a EventId, + room_id: OwnedRoomId, + event_id: OwnedEventId, rel_type: RelationType, event_type: RoomEventType, ) -> Self { diff --git a/crates/ruma-client-api/src/room/aliases.rs b/crates/ruma-client-api/src/room/aliases.rs index 9b14d250..55918b75 100644 --- a/crates/ruma-client-api/src/room/aliases.rs +++ b/crates/ruma-client-api/src/room/aliases.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomAliasId, RoomId, + metadata, OwnedRoomAliasId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -25,10 +25,10 @@ pub mod v3 { /// Request type for the `aliases` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room ID to get aliases of. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `aliases` endpoint. @@ -38,9 +38,9 @@ pub mod v3 { pub aliases: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/room/create_room.rs b/crates/ruma-client-api/src/room/create_room.rs index 4bea63e5..2060e895 100644 --- a/crates/ruma-client-api/src/room/create_room.rs +++ b/crates/ruma-client-api/src/room/create_room.rs @@ -24,11 +24,7 @@ pub mod v3 { }; use serde::{Deserialize, Serialize}; - use crate::{ - membership::{IncomingInvite3pid, Invite3pid}, - room::Visibility, - PrivOwnedStr, - }; + use crate::{membership::Invite3pid, room::Visibility, PrivOwnedStr}; const METADATA: Metadata = metadata! { method: POST, @@ -43,7 +39,7 @@ pub mod v3 { /// Request type for the `create_room` endpoint. #[request(error = crate::Error)] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Extra keys to be added to the content of the `m.room.create`. #[serde(default, skip_serializing_if = "Option::is_none")] pub creation_content: Option>, @@ -52,17 +48,17 @@ pub mod v3 { /// /// Takes precedence over events set by preset, but gets overridden by name and topic keys. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub initial_state: &'a [Raw], + pub initial_state: Vec>, /// A list of user IDs to invite to the room. /// /// This will tell the server to invite everyone in the list to the newly created room. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub invite: &'a [OwnedUserId], + pub invite: Vec, /// List of third party IDs of users to invite. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub invite_3pid: &'a [Invite3pid<'a>], + pub invite_3pid: Vec, /// If set, this sets the `is_direct` flag on room invites. #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] @@ -71,7 +67,7 @@ pub mod v3 { /// If this is included, an `m.room.name` event will be sent into the room to indicate the /// name of the room. #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option<&'a str>, + pub name: Option, /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] @@ -83,18 +79,18 @@ pub mod v3 { /// The desired room alias local part. #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias_name: Option<&'a str>, + pub room_alias_name: Option, /// Room version to set for the room. /// /// Defaults to homeserver's default if not specified. #[serde(skip_serializing_if = "Option::is_none")] - pub room_version: Option<&'a RoomVersionId>, + pub room_version: Option, /// If this is included, an `m.room.topic` event will be sent into the room to indicate /// the topic for the room. #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option<&'a str>, + pub topic: Option, /// A public visibility indicates that the room will be shown in the published room list. /// @@ -111,7 +107,7 @@ pub mod v3 { pub room_id: OwnedRoomId, } - impl Request<'_> { + impl Request { /// Creates a new `Request` will all-default parameters. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/room/get_room_event.rs b/crates/ruma-client-api/src/room/get_room_event.rs index f793f4ae..d3fe00c1 100644 --- a/crates/ruma-client-api/src/room/get_room_event.rs +++ b/crates/ruma-client-api/src/room/get_room_event.rs @@ -12,7 +12,7 @@ pub mod v3 { events::AnyTimelineEvent, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -27,14 +27,14 @@ pub mod v3 { /// Request type for the `get_room_event` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the room the event is in. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The ID of the event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, } /// Response type for the `get_room_event` endpoint. @@ -45,9 +45,9 @@ pub mod v3 { pub event: Raw, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and event ID. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-client-api/src/room/report_content.rs b/crates/ruma-client-api/src/room/report_content.rs index 0a9b5086..14be79ea 100644 --- a/crates/ruma-client-api/src/room/report_content.rs +++ b/crates/ruma-client-api/src/room/report_content.rs @@ -10,7 +10,7 @@ pub mod v3 { use js_int::Int; use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -25,14 +25,14 @@ pub mod v3 { /// Request type for the `report_content` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Room in which the event to be reported is located. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// Event to report. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// Integer between -100 and 0 rating offensivness. pub score: Option, @@ -40,7 +40,7 @@ pub mod v3 { /// Reason to report content. /// /// May be blank. - pub reason: Option<&'a str>, + pub reason: Option, } /// Response type for the `report_content` endpoint. @@ -48,13 +48,13 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, event ID, score and reason. pub fn new( - room_id: &'a RoomId, - event_id: &'a EventId, + room_id: OwnedRoomId, + event_id: OwnedEventId, score: Option, - reason: Option<&'a str>, + reason: Option, ) -> Self { Self { room_id, event_id, score, reason } } diff --git a/crates/ruma-client-api/src/room/upgrade_room.rs b/crates/ruma-client-api/src/room/upgrade_room.rs index 8273d2af..fff9d03f 100644 --- a/crates/ruma-client-api/src/room/upgrade_room.rs +++ b/crates/ruma-client-api/src/room/upgrade_room.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, RoomId, RoomVersionId, + metadata, OwnedRoomId, RoomVersionId, }; const METADATA: Metadata = metadata! { @@ -24,13 +24,13 @@ pub mod v3 { /// Request type for the `upgrade_room` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// ID of the room to be upgraded. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// New version for the room. - pub new_version: &'a RoomVersionId, + pub new_version: RoomVersionId, } /// Response type for the `upgrade_room` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { pub replacement_room: OwnedRoomId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID and new room version. - pub fn new(room_id: &'a RoomId, new_version: &'a RoomVersionId) -> Self { + pub fn new(room_id: OwnedRoomId, new_version: RoomVersionId) -> Self { Self { room_id, new_version } } } diff --git a/crates/ruma-client-api/src/search/search_events.rs b/crates/ruma-client-api/src/search/search_events.rs index e0da523f..bdd6700c 100644 --- a/crates/ruma-client-api/src/search/search_events.rs +++ b/crates/ruma-client-api/src/search/search_events.rs @@ -14,15 +14,12 @@ pub mod v3 { api::{request, response, Metadata}, events::{AnyStateEvent, AnyTimelineEvent}, metadata, - serde::{Incoming, Raw, StringEnum}, + serde::{Raw, StringEnum}, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedUserId, }; use serde::{Deserialize, Serialize}; - use crate::{ - filter::{IncomingRoomEventFilter, RoomEventFilter}, - PrivOwnedStr, - }; + use crate::{filter::RoomEventFilter, PrivOwnedStr}; const METADATA: Metadata = metadata! { method: POST, @@ -36,15 +33,15 @@ pub mod v3 { /// Request type for the `search` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The point to return events from. /// /// If given, this should be a `next_batch` result from a previous call to this endpoint. #[ruma_api(query)] - pub next_batch: Option<&'a str>, + pub next_batch: Option, /// Describes which categories to search in and their criteria. - pub search_categories: Categories<'a>, + pub search_categories: Categories, } /// Response type for the `search` endpoint. @@ -54,9 +51,9 @@ pub mod v3 { pub search_categories: ResultCategories, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given categories. - pub fn new(search_categories: Categories<'a>) -> Self { + pub fn new(search_categories: Categories) -> Self { Self { next_batch: None, search_categories } } } @@ -69,15 +66,15 @@ pub mod v3 { } /// Categories of events that can be searched for. - #[derive(Clone, Debug, Default, Incoming, Serialize)] + #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - pub struct Categories<'a> { + pub struct Categories { /// Criteria for searching room events. #[serde(skip_serializing_if = "Option::is_none")] - pub room_events: Option>, + pub room_events: Option, } - impl Categories<'_> { + impl Categories { /// Creates an empty `Categories`. pub fn new() -> Self { Default::default() @@ -85,21 +82,21 @@ pub mod v3 { } /// Criteria for searching a category of events. - #[derive(Clone, Debug, Incoming, Serialize)] + #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - pub struct Criteria<'a> { + pub struct Criteria { /// The string to search events for. - pub search_term: &'a str, + pub search_term: String, /// The keys to search for. /// /// Defaults to all keys. #[serde(skip_serializing_if = "Option::is_none")] - pub keys: Option<&'a [SearchKeys]>, + pub keys: Option>, /// A `Filter` to apply to the search. #[serde(skip_serializing_if = "RoomEventFilter::is_empty")] - pub filter: RoomEventFilter<'a>, + pub filter: RoomEventFilter, /// The order in which to search for results. #[serde(skip_serializing_if = "Option::is_none")] @@ -115,12 +112,12 @@ pub mod v3 { /// Requests that the server partitions the result set based on the provided list of keys. #[serde(default, skip_serializing_if = "Groupings::is_empty")] - pub groupings: Groupings<'a>, + pub groupings: Groupings, } - impl<'a> Criteria<'a> { + impl Criteria { /// Creates a new `Criteria` with the given search term. - pub fn new(search_term: &'a str) -> Self { + pub fn new(search_term: String) -> Self { Self { search_term, keys: None, @@ -268,16 +265,15 @@ pub mod v3 { } /// Requests that the server partitions the result set based on the provided list of keys. - #[derive(Clone, Default, Debug, Incoming, Serialize)] - #[incoming_derive(Default)] + #[derive(Clone, Default, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - pub struct Groupings<'a> { + pub struct Groupings { /// List of groups to request. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub group_by: &'a [Grouping], + pub group_by: Vec, } - impl Groupings<'_> { + impl Groupings { /// Creates an empty `Groupings`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/server/get_user_info.rs b/crates/ruma-client-api/src/server/get_user_info.rs index 416b5fdd..9abd065f 100644 --- a/crates/ruma-client-api/src/server/get_user_info.rs +++ b/crates/ruma-client-api/src/server/get_user_info.rs @@ -11,7 +11,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, MilliSecondsSinceUnixEpoch, OwnedUserId, UserId, + metadata, MilliSecondsSinceUnixEpoch, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `get_user_info` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user to look up. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_user_info` endpoint. @@ -46,9 +46,9 @@ pub mod v3 { pub devices: BTreeMap, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-client-api/src/session/login.rs b/crates/ruma-client-api/src/session/login.rs index 97fa60fe..b6a4335c 100644 --- a/crates/ruma-client-api/src/session/login.rs +++ b/crates/ruma-client-api/src/session/login.rs @@ -12,8 +12,8 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, metadata, - serde::{Incoming, JsonObject}, - DeviceId, OwnedDeviceId, OwnedServerName, OwnedUserId, + serde::JsonObject, + OwnedDeviceId, OwnedServerName, OwnedUserId, }; use serde::{ de::{self, DeserializeOwned}, @@ -21,7 +21,7 @@ pub mod v3 { }; use serde_json::Value as JsonValue; - use crate::uiaa::{IncomingUserIdentifier, UserIdentifier}; + use crate::uiaa::UserIdentifier; const METADATA: Metadata = metadata! { method: POST, @@ -35,20 +35,20 @@ pub mod v3 { /// Request type for the `login` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The authentication mechanism. #[serde(flatten)] - pub login_info: LoginInfo<'a>, + pub login_info: LoginInfo, /// ID of the client device #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, + pub device_id: Option, /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, + pub initial_device_display_name: Option, /// If set to `true`, the client supports [refresh tokens]. /// @@ -110,9 +110,9 @@ pub mod v3 { )] pub expires_in: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given login info. - pub fn new(login_info: LoginInfo<'a>) -> Self { + pub fn new(login_info: LoginInfo) -> Self { Self { login_info, device_id: None, @@ -138,40 +138,24 @@ pub mod v3 { } /// The authentication mechanism. - /// - /// To construct the custom `LoginInfo` variant you first have to construct - /// [`IncomingLoginInfo::new`] and then call [`IncomingLoginInfo::to_outgoing`] on it. - #[derive(Clone, Incoming, Serialize)] + #[derive(Clone, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Debug, !Deserialize)] #[serde(untagged)] - pub enum LoginInfo<'a> { + pub enum LoginInfo { /// An identifier and password are supplied to authenticate. - Password(Password<'a>), + Password(Password), /// Token-based login. - Token(Token<'a>), + Token(Token), /// Application Service-specific login. - ApplicationService(ApplicationService<'a>), + ApplicationService(ApplicationService), #[doc(hidden)] - _Custom(CustomLoginInfo<'a>), + _Custom(CustomLoginInfo), } - impl fmt::Debug for LoginInfo<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // Print `Password { .. }` instead of `Password(Password { .. })` - match self { - Self::Password(inner) => inner.fmt(f), - Self::Token(inner) => inner.fmt(f), - Self::ApplicationService(inner) => inner.fmt(f), - Self::_Custom(inner) => inner.fmt(f), - } - } - } - - impl IncomingLoginInfo { + impl LoginInfo { /// Creates a new `IncomingLoginInfo` with the given `login_type` string, session and data. /// /// Prefer to use the public variants of `IncomingLoginInfo` where possible; this @@ -191,28 +175,12 @@ pub mod v3 { "m.login.application_service" => { Self::ApplicationService(serde_json::from_value(JsonValue::Object(data))?) } - _ => Self::_Custom(IncomingCustomLoginInfo { - login_type: login_type.into(), - extra: data, - }), + _ => Self::_Custom(CustomLoginInfo { login_type: login_type.into(), extra: data }), }) } - - /// Convert `IncomingLoginInfo` to `LoginInfo`. - pub fn to_outgoing(&self) -> LoginInfo<'_> { - match self { - Self::Password(a) => LoginInfo::Password(a.to_outgoing()), - Self::Token(a) => LoginInfo::Token(a.to_outgoing()), - Self::ApplicationService(a) => LoginInfo::ApplicationService(a.to_outgoing()), - Self::_Custom(a) => LoginInfo::_Custom(CustomLoginInfo { - login_type: &a.login_type, - extra: &a.extra, - }), - } - } } - impl fmt::Debug for IncomingLoginInfo { + impl fmt::Debug for LoginInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Print `Password { .. }` instead of `Password(Password { .. })` match self { @@ -224,7 +192,7 @@ pub mod v3 { } } - impl<'de> Deserialize<'de> for IncomingLoginInfo { + impl<'de> Deserialize<'de> for LoginInfo { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -248,142 +216,84 @@ pub mod v3 { } /// An identifier and password to supply as authentication. - #[derive(Clone, Incoming, Serialize)] + #[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Debug)] #[serde(tag = "type", rename = "m.login.password")] - pub struct Password<'a> { + pub struct Password { /// Identification information for the user. - pub identifier: UserIdentifier<'a>, + pub identifier: UserIdentifier, /// The password. - pub password: &'a str, + pub password: String, } - impl<'a> Password<'a> { + impl Password { /// Creates a new `Password` with the given identifier and password. - pub fn new(identifier: UserIdentifier<'a>, password: &'a str) -> Self { + pub fn new(identifier: UserIdentifier, password: String) -> Self { Self { identifier, password } } } - impl IncomingPassword { - /// Convert `IncomingPassword` to `Password`. - fn to_outgoing(&self) -> Password<'_> { - Password { identifier: self.identifier.to_outgoing(), password: &self.password } - } - } - - impl<'a> fmt::Debug for Password<'a> { + impl fmt::Debug for Password { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { identifier, password: _ } = self; f.debug_struct("Password").field("identifier", identifier).finish_non_exhaustive() } } - impl fmt::Debug for IncomingPassword { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { identifier, password: _ } = self; - f.debug_struct("IncomingPassword") - .field("identifier", identifier) - .finish_non_exhaustive() - } - } - /// A token to supply as authentication. - #[derive(Clone, Incoming, Serialize)] + #[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Debug)] #[serde(tag = "type", rename = "m.login.token")] - pub struct Token<'a> { + pub struct Token { /// The token. - pub token: &'a str, + pub token: String, } - impl<'a> Token<'a> { + impl Token { /// Creates a new `Token` with the given token. - pub fn new(token: &'a str) -> Self { + pub fn new(token: String) -> Self { Self { token } } } - impl IncomingToken { - /// Convert `IncomingToken` to `Token`. - fn to_outgoing(&self) -> Token<'_> { - Token { token: &self.token } - } - } - - impl<'a> fmt::Debug for Token<'a> { + impl fmt::Debug for Token { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { token: _ } = self; f.debug_struct("Token").finish_non_exhaustive() } } - impl fmt::Debug for IncomingToken { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { token: _ } = self; - f.debug_struct("IncomingToken").finish_non_exhaustive() - } - } - /// An identifier to supply for Application Service authentication. - #[derive(Clone, Debug, Incoming, Serialize)] + #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.application_service")] - pub struct ApplicationService<'a> { + pub struct ApplicationService { /// Identification information for the user. - pub identifier: UserIdentifier<'a>, + pub identifier: UserIdentifier, } - impl<'a> ApplicationService<'a> { + impl ApplicationService { /// Creates a new `ApplicationService` with the given identifier. - pub fn new(identifier: UserIdentifier<'a>) -> Self { + pub fn new(identifier: UserIdentifier) -> Self { Self { identifier } } } - impl IncomingApplicationService { - /// Convert `IncomingApplicationService` to `ApplicationService`. - fn to_outgoing(&self) -> ApplicationService<'_> { - ApplicationService { identifier: self.identifier.to_outgoing() } - } - } - #[doc(hidden)] - #[derive(Clone, Serialize)] + #[derive(Clone, Deserialize, Serialize)] #[non_exhaustive] - pub struct CustomLoginInfo<'a> { - #[serde(rename = "type")] - login_type: &'a str, - #[serde(flatten)] - extra: &'a JsonObject, - } - - impl<'a> fmt::Debug for CustomLoginInfo<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { login_type, extra: _ } = self; - f.debug_struct("CustomLoginInfo") - .field("login_type", login_type) - .finish_non_exhaustive() - } - } - - #[doc(hidden)] - #[derive(Clone, Deserialize)] - #[non_exhaustive] - pub struct IncomingCustomLoginInfo { + pub struct CustomLoginInfo { #[serde(rename = "type")] login_type: String, #[serde(flatten)] extra: JsonObject, } - impl fmt::Debug for IncomingCustomLoginInfo { + impl fmt::Debug for CustomLoginInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { login_type, extra: _ } = self; - f.debug_struct("IncomingCustomLoginInfo") + f.debug_struct("CustomLoginInfo") .field("login_type", login_type) .finish_non_exhaustive() } @@ -444,8 +354,8 @@ pub mod v3 { use assert_matches::assert_matches; use serde_json::{from_value as from_json_value, json}; - use super::{IncomingLoginInfo, IncomingToken}; - use crate::uiaa::IncomingUserIdentifier; + use super::{LoginInfo, Token}; + use crate::uiaa::UserIdentifier; #[test] fn deserialize_login_type() { @@ -459,11 +369,11 @@ pub mod v3 { "password": "ilovebananas" })) .unwrap(), - IncomingLoginInfo::Password(login) => login + LoginInfo::Password(login) => login ); let user = assert_matches!( login.identifier, - IncomingUserIdentifier::UserIdOrLocalpart(user) => user + UserIdentifier::UserIdOrLocalpart(user) => user ); assert_eq!(user, "cheeky_monkey"); assert_eq!(login.password, "ilovebananas"); @@ -474,7 +384,7 @@ pub mod v3 { "token": "1234567890abcdef" })) .unwrap(), - IncomingLoginInfo::Token(IncomingToken { token }) => token + LoginInfo::Token(Token { token }) => token ); assert_eq!(token, "1234567890abcdef"); } @@ -489,9 +399,9 @@ pub mod v3 { use crate::uiaa::UserIdentifier; let req: http::Request> = Request { - login_info: LoginInfo::Token(Token { token: "0xdeadbeef" }), + login_info: LoginInfo::Token(Token { token: "0xdeadbeef".to_owned() }), device_id: None, - initial_device_display_name: Some("test"), + initial_device_display_name: Some("test".to_owned()), refresh_token: false, } .try_into_http_request( @@ -513,11 +423,11 @@ pub mod v3 { let req: http::Request> = Request { login_info: LoginInfo::Password(Password { - identifier: UserIdentifier::Email { address: "hello@example.com" }, - password: "deadbeef", + identifier: UserIdentifier::Email { address: "hello@example.com".to_owned() }, + password: "deadbeef".to_owned(), }), device_id: None, - initial_device_display_name: Some("test"), + initial_device_display_name: Some("test".to_owned()), refresh_token: false, } .try_into_http_request( diff --git a/crates/ruma-client-api/src/session/login_fallback.rs b/crates/ruma-client-api/src/session/login_fallback.rs index d8ba6238..cb389da1 100644 --- a/crates/ruma-client-api/src/session/login_fallback.rs +++ b/crates/ruma-client-api/src/session/login_fallback.rs @@ -6,7 +6,7 @@ use ruma_common::{ api::{request, response, Metadata}, - metadata, DeviceId, + metadata, OwnedDeviceId, }; const METADATA: Metadata = metadata! { @@ -21,18 +21,18 @@ const METADATA: Metadata = metadata! { /// Request type for the `login_fallback` endpoint. #[request(error = crate::Error)] #[derive(Default)] -pub struct Request<'a> { +pub struct Request { /// ID of the client device. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, + pub device_id: Option, /// A display name to assign to the newly-created device. /// /// Ignored if `device_id` corresponds to a known device. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, + pub initial_device_display_name: Option, } /// Response type for the `login_fallback` endpoint. @@ -43,11 +43,11 @@ pub struct Response { pub body: Vec, } -impl<'a> Request<'a> { +impl Request { /// Creates a new `Request` with the given auth type and session ID. pub fn new( - device_id: Option<&'a DeviceId>, - initial_device_display_name: Option<&'a str>, + device_id: Option, + initial_device_display_name: Option, ) -> Self { Self { device_id, initial_device_display_name } } diff --git a/crates/ruma-client-api/src/session/refresh_token.rs b/crates/ruma-client-api/src/session/refresh_token.rs index 5b15e4b9..0bd6a4a8 100644 --- a/crates/ruma-client-api/src/session/refresh_token.rs +++ b/crates/ruma-client-api/src/session/refresh_token.rs @@ -44,9 +44,9 @@ pub mod v3 { /// Request type for the `refresh` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The refresh token. - pub refresh_token: &'a str, + pub refresh_token: String, } /// Response type for the `refresh` endpoint. @@ -72,9 +72,9 @@ pub mod v3 { pub expires_in_ms: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given refresh token. - pub fn new(refresh_token: &'a str) -> Self { + pub fn new(refresh_token: String) -> Self { Self { refresh_token } } } diff --git a/crates/ruma-client-api/src/session/sso_login.rs b/crates/ruma-client-api/src/session/sso_login.rs index b1aa050d..b39aeeb4 100644 --- a/crates/ruma-client-api/src/session/sso_login.rs +++ b/crates/ruma-client-api/src/session/sso_login.rs @@ -23,12 +23,12 @@ pub mod v3 { /// Request type for the `sso_login` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// URL to which the homeserver should return the user after completing /// authentication with the SSO identity provider. #[ruma_api(query)] #[serde(rename = "redirectUrl")] - pub redirect_url: &'a str, + pub redirect_url: String, } /// Response type for the `sso_login` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { pub location: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given redirect URL. - pub fn new(redirect_url: &'a str) -> Self { + pub fn new(redirect_url: String) -> Self { Self { redirect_url } } } @@ -61,13 +61,14 @@ pub mod v3 { #[test] fn serialize_sso_login_request_uri() { - let req: http::Request> = Request { redirect_url: "https://example.com/sso" } - .try_into_http_request( - "https://homeserver.tld", - SendAccessToken::None, - &[MatrixVersion::V1_1], - ) - .unwrap(); + let req: http::Request> = + Request { redirect_url: "https://example.com/sso".to_owned() } + .try_into_http_request( + "https://homeserver.tld", + SendAccessToken::None, + &[MatrixVersion::V1_1], + ) + .unwrap(); assert_eq!( req.uri().to_string(), diff --git a/crates/ruma-client-api/src/session/sso_login_with_provider.rs b/crates/ruma-client-api/src/session/sso_login_with_provider.rs index d620c4ef..75c51e3e 100644 --- a/crates/ruma-client-api/src/session/sso_login_with_provider.rs +++ b/crates/ruma-client-api/src/session/sso_login_with_provider.rs @@ -25,16 +25,16 @@ pub mod v3 { /// Request type for the `sso_login_with_provider` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the provider to use for SSO login. #[ruma_api(path)] - pub idp_id: &'a str, + pub idp_id: String, /// URL to which the homeserver should return the user after completing /// authentication with the SSO identity provider. #[ruma_api(query)] #[serde(rename = "redirectUrl")] - pub redirect_url: &'a str, + pub redirect_url: String, } /// Response type for the `sso_login_with_provider` endpoint. @@ -45,9 +45,9 @@ pub mod v3 { pub location: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given identity provider ID and redirect URL. - pub fn new(idp_id: &'a str, redirect_url: &'a str) -> Self { + pub fn new(idp_id: String, redirect_url: String) -> Self { Self { idp_id, redirect_url } } } @@ -67,13 +67,16 @@ pub mod v3 { #[test] fn serialize_sso_login_with_provider_request_uri() { - let req = Request { idp_id: "provider", redirect_url: "https://example.com/sso" } - .try_into_http_request::>( - "https://homeserver.tld", - SendAccessToken::None, - &[MatrixVersion::V1_1], - ) - .unwrap(); + let req = Request { + idp_id: "provider".to_owned(), + redirect_url: "https://example.com/sso".to_owned(), + } + .try_into_http_request::>( + "https://homeserver.tld", + SendAccessToken::None, + &[MatrixVersion::V1_1], + ) + .unwrap(); assert_eq!( req.uri().to_string(), diff --git a/crates/ruma-client-api/src/space/get_hierarchy.rs b/crates/ruma-client-api/src/space/get_hierarchy.rs index 54f9739d..6b2f8950 100644 --- a/crates/ruma-client-api/src/space/get_hierarchy.rs +++ b/crates/ruma-client-api/src/space/get_hierarchy.rs @@ -10,7 +10,7 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, + metadata, OwnedRoomId, }; use crate::space::SpaceHierarchyRoomsChunk; @@ -27,17 +27,17 @@ pub mod v1 { /// Request type for the `hierarchy` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room ID of the space to get a hierarchy for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// A pagination token from a previous result. /// /// If specified, `max_depth` and `suggested_only` cannot be changed from the first /// request. #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// The maximum number of rooms to include per response. #[ruma_api(query)] @@ -73,9 +73,9 @@ pub mod v1 { pub rooms: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, from: None, limit: None, max_depth: None, suggested_only: false } } } diff --git a/crates/ruma-client-api/src/state/get_state_events.rs b/crates/ruma-client-api/src/state/get_state_events.rs index 91b57429..507950f2 100644 --- a/crates/ruma-client-api/src/state/get_state_events.rs +++ b/crates/ruma-client-api/src/state/get_state_events.rs @@ -12,7 +12,7 @@ pub mod v3 { events::AnyStateEvent, metadata, serde::Raw, - RoomId, + OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `get_state_events` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room to look up the state for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `get_state_events` endpoint. @@ -45,9 +45,9 @@ pub mod v3 { pub room_state: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/state/get_state_events_for_key.rs b/crates/ruma-client-api/src/state/get_state_events_for_key.rs index 7b6044fa..1e4cd406 100644 --- a/crates/ruma-client-api/src/state/get_state_events_for_key.rs +++ b/crates/ruma-client-api/src/state/get_state_events_for_key.rs @@ -11,8 +11,8 @@ pub mod v3 { api::{response, Metadata}, events::{AnyStateEventContent, StateEventType}, metadata, - serde::{Incoming, Raw}, - RoomId, + serde::Raw, + OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -26,23 +26,22 @@ pub mod v3 { }; /// Request type for the `get_state_events_for_key` endpoint. - #[derive(Clone, Debug, Incoming)] + #[derive(Clone, Debug)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize)] - pub struct Request<'a> { + pub struct Request { /// The room to look up the state for. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The type of state to look up. pub event_type: StateEventType, /// The key of the state to look up. - pub state_key: &'a str, + pub state_key: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, event type and state key. - pub fn new(room_id: &'a RoomId, event_type: StateEventType, state_key: &'a str) -> Self { + pub fn new(room_id: OwnedRoomId, event_type: StateEventType, state_key: String) -> Self { Self { room_id, event_type, state_key } } } @@ -66,7 +65,7 @@ pub mod v3 { } #[cfg(feature = "client")] - impl<'a> ruma_common::api::OutgoingRequest for Request<'a> { + impl ruma_common::api::OutgoingRequest for Request { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -104,7 +103,7 @@ pub mod v3 { } #[cfg(feature = "server")] - impl ruma_common::api::IncomingRequest for IncomingRequest { + impl ruma_common::api::IncomingRequest for Request { type EndpointError = crate::Error; type OutgoingResponse = Response; @@ -118,8 +117,6 @@ pub mod v3 { B: AsRef<[u8]>, S: AsRef, { - use ruma_common::OwnedRoomId; - // FIXME: find a way to make this if-else collapse with serde recognizing trailing // Option let (room_id, event_type, state_key): (OwnedRoomId, StateEventType, String) = diff --git a/crates/ruma-client-api/src/state/send_state_event.rs b/crates/ruma-client-api/src/state/send_state_event.rs index 6653d0ca..76be7605 100644 --- a/crates/ruma-client-api/src/state/send_state_event.rs +++ b/crates/ruma-client-api/src/state/send_state_event.rs @@ -13,8 +13,8 @@ pub mod v3 { api::{response, Metadata}, events::{AnyStateEventContent, StateEventContent, StateEventType}, metadata, - serde::{Incoming, Raw}, - MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, + serde::Raw, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -29,18 +29,17 @@ pub mod v3 { }; /// Request type for the `send_state_event` endpoint. - #[derive(Clone, Debug, Incoming)] + #[derive(Clone, Debug)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize)] - pub struct Request<'a> { + pub struct Request { /// The room to set the state in. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The type of event to send. pub event_type: StateEventType, /// The state_key for the state to send. - pub state_key: &'a str, + pub state_key: String, /// The event content to send. pub body: Raw, @@ -55,7 +54,7 @@ pub mod v3 { pub timestamp: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id, state key and event content. /// /// # Errors @@ -63,9 +62,9 @@ pub mod v3 { /// Since `Request` stores the request body in serialized form, this function can fail if /// `T`s [`Serialize`][serde::Serialize] implementation can fail. pub fn new( - room_id: &'a RoomId, - state_key: &'a K, - content: &'a T, + room_id: OwnedRoomId, + state_key: &K, + content: &T, ) -> serde_json::Result where T: StateEventContent, @@ -74,7 +73,7 @@ pub mod v3 { { Ok(Self { room_id, - state_key: state_key.as_ref(), + state_key: state_key.as_ref().to_owned(), event_type: content.event_type(), body: Raw::from_json(to_raw_json_value(content)?), timestamp: None, @@ -84,9 +83,9 @@ pub mod v3 { /// Creates a new `Request` with the given room id, event type, state key and raw event /// content. pub fn new_raw( - room_id: &'a RoomId, + room_id: OwnedRoomId, event_type: StateEventType, - state_key: &'a str, + state_key: String, body: Raw, ) -> Self { Self { room_id, event_type, state_key, body, timestamp: None } @@ -108,7 +107,7 @@ pub mod v3 { } #[cfg(feature = "client")] - impl<'a> ruma_common::api::OutgoingRequest for Request<'a> { + impl ruma_common::api::OutgoingRequest for Request { type EndpointError = crate::Error; type IncomingResponse = Response; @@ -151,7 +150,7 @@ pub mod v3 { } #[cfg(feature = "server")] - impl ruma_common::api::IncomingRequest for IncomingRequest { + impl ruma_common::api::IncomingRequest for Request { type EndpointError = crate::Error; type OutgoingResponse = Response; @@ -165,8 +164,6 @@ pub mod v3 { B: AsRef<[u8]>, S: AsRef, { - use ruma_common::OwnedRoomId; - // FIXME: find a way to make this if-else collapse with serde recognizing trailing // Option let (room_id, event_type, state_key): (OwnedRoomId, StateEventType, String) = @@ -219,7 +216,7 @@ pub mod v3 { // This used to panic in make_endpoint_url because of a mismatch in the path parameter count let req = Request::new( - room_id!("!room:server.tld"), + room_id!("!room:server.tld").to_owned(), &EmptyStateKey, &RoomNameEventContent::new(Some("Test room".to_owned())), ) diff --git a/crates/ruma-client-api/src/sync/sync_events/v3.rs b/crates/ruma-client-api/src/sync/sync_events/v3.rs index 82d965bf..5e5af48f 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v3.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v3.rs @@ -15,12 +15,12 @@ use ruma_common::{ }, metadata, presence::PresenceState, - serde::{Incoming, Raw}, + serde::Raw, DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId, }; use serde::{Deserialize, Serialize}; -use crate::filter::{FilterDefinition, IncomingFilterDefinition}; +use crate::filter::FilterDefinition; const METADATA: Metadata = metadata! { method: GET, @@ -35,11 +35,11 @@ const METADATA: Metadata = metadata! { /// Request type for the `sync` endpoint. #[request(error = crate::Error)] #[derive(Default)] -pub struct Request<'a> { +pub struct Request { /// A filter represented either as its full JSON definition or the ID of a saved filter. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub filter: Option<&'a Filter<'a>>, + pub filter: Option, /// A point in time to continue a sync from. /// @@ -47,7 +47,7 @@ pub struct Request<'a> { /// request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub since: Option<&'a str>, + pub since: Option, /// Controls whether to include the full state for all rooms the user is a member of. #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] @@ -59,7 +59,7 @@ pub struct Request<'a> { /// Defaults to `PresenceState::Online`. #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] #[ruma_api(query)] - pub set_presence: &'a PresenceState, + pub set_presence: PresenceState, /// The maximum time to poll in milliseconds before returning this request. #[serde( @@ -112,7 +112,7 @@ pub struct Response { pub device_unused_fallback_key_types: Option>, } -impl Request<'_> { +impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() @@ -136,11 +136,11 @@ impl Response { } /// A filter represented either as its full JSON definition or the ID of a saved filter. -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[allow(clippy::large_enum_variant)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(untagged)] -pub enum Filter<'a> { +pub enum Filter { // The filter definition needs to be (de)serialized twice because it is a URL-encoded JSON // string. Since #[ruma_api(query)] only does the latter and this is a very uncommon // setup, we implement it through custom serde logic for this specific enum variant rather @@ -153,20 +153,20 @@ pub enum Filter<'a> { // says. (there are probably some corner cases like leading whitespace) /// A complete filter definition serialized to JSON. #[serde(with = "ruma_common::serde::json_string")] - FilterDefinition(FilterDefinition<'a>), + FilterDefinition(FilterDefinition), /// The ID of a filter saved on the server. - FilterId(&'a str), + FilterId(String), } -impl<'a> From> for Filter<'a> { - fn from(def: FilterDefinition<'a>) -> Self { +impl From for Filter { + fn from(def: FilterDefinition) -> Self { Self::FilterDefinition(def) } } -impl<'a> From<&'a str> for Filter<'a> { - fn from(id: &'a str) -> Self { +impl From for Filter { + fn from(id: String) -> Self { Self::FilterId(id) } } @@ -628,10 +628,10 @@ mod client_tests { #[test] fn serialize_all_params() { let req: http::Request> = Request { - filter: Some(&Filter::FilterId("66696p746572")), - since: Some("s72594_4483_1934"), + filter: Some(Filter::FilterId("66696p746572".to_owned())), + since: Some("s72594_4483_1934".to_owned()), full_state: true, - set_presence: &PresenceState::Offline, + set_presence: PresenceState::Offline, timeout: Some(Duration::from_millis(30000)), } .try_into_http_request( @@ -660,7 +660,7 @@ mod server_tests { use assert_matches::assert_matches; use ruma_common::{api::IncomingRequest as _, presence::PresenceState}; - use super::{IncomingFilter, IncomingRequest}; + use super::{Filter, Request}; #[test] fn deserialize_all_query_params() { @@ -678,13 +678,13 @@ mod server_tests { .build() .unwrap(); - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(), &[] as &[String], ) .unwrap(); - let id = assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) => id); + let id = assert_matches!(req.filter, Some(Filter::FilterId(id)) => id); assert_eq!(id, "myfilter"); assert_eq!(req.since.as_deref(), Some("myts")); assert!(!req.full_state); @@ -701,7 +701,7 @@ mod server_tests { .build() .unwrap(); - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(), &[] as &[String], ) @@ -727,13 +727,13 @@ mod server_tests { .build() .unwrap(); - let req = IncomingRequest::try_from_http_request( + let req = Request::try_from_http_request( http::Request::builder().uri(uri).body(&[] as &[u8]).unwrap(), &[] as &[String], ) .unwrap(); - let id = assert_matches!(req.filter, Some(IncomingFilter::FilterId(id)) => id); + let id = assert_matches!(req.filter, Some(Filter::FilterId(id)) => id); assert_eq!(id, "EOKFFmdZYF"); assert_eq!(req.since, None); assert!(!req.full_state); diff --git a/crates/ruma-client-api/src/sync/sync_events/v4.rs b/crates/ruma-client-api/src/sync/sync_events/v4.rs index 739d1bf8..9d7b6fa9 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v4.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v4.rs @@ -33,19 +33,19 @@ const METADATA: Metadata = metadata! { /// Request type for the `sync` endpoint. #[request(error = crate::Error)] #[derive(Default)] -pub struct Request<'a> { +pub struct Request { /// A point in time to continue a sync from. /// /// Should be a token from the `pos` field of a previous `/sync` /// response. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub pos: Option<&'a str>, + pub pos: Option, /// Allows clients to know what request params reached the server, /// functionally similar to txn IDs on /send for events. #[serde(skip_serializing_if = "Option::is_none")] - pub txn_id: Option<&'a str>, + pub txn_id: Option, /// The maximum time to poll before responding to this request. #[serde(with = "opt_ms", default, skip_serializing_if = "Option::is_none")] @@ -53,7 +53,7 @@ pub struct Request<'a> { pub timeout: Option, /// The lists of rooms we're interested in. - pub lists: &'a [SyncRequestList], + pub lists: Vec, /// Specific rooms and event types that we want to receive events from. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -61,7 +61,7 @@ pub struct Request<'a> { /// Specific rooms we no longer want to receive events from. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub unsubscribe_rooms: &'a [OwnedRoomId], + pub unsubscribe_rooms: Vec, /// Extensions API. #[serde(default, skip_serializing_if = "ExtensionsConfig::is_empty")] @@ -92,7 +92,7 @@ pub struct Response { pub extensions: Extensions, } -impl Request<'_> { +impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-client-api/src/tag/create_tag.rs b/crates/ruma-client-api/src/tag/create_tag.rs index 85be26dc..0d9fccee 100644 --- a/crates/ruma-client-api/src/tag/create_tag.rs +++ b/crates/ruma-client-api/src/tag/create_tag.rs @@ -10,7 +10,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, events::tag::TagInfo, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -25,18 +25,18 @@ pub mod v3 { /// Request type for the `create_tag` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The ID of the user creating the tag. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The room to tag. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The name of the tag to create. #[ruma_api(path)] - pub tag: &'a str, + pub tag: String, /// Info about the tag. #[ruma_api(body)] @@ -48,12 +48,12 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID, room ID, tag and tag info. pub fn new( - user_id: &'a UserId, - room_id: &'a RoomId, - tag: &'a str, + user_id: OwnedUserId, + room_id: OwnedRoomId, + tag: String, tag_info: TagInfo, ) -> Self { Self { user_id, room_id, tag, tag_info } diff --git a/crates/ruma-client-api/src/tag/delete_tag.rs b/crates/ruma-client-api/src/tag/delete_tag.rs index a8ca522c..23cb6e95 100644 --- a/crates/ruma-client-api/src/tag/delete_tag.rs +++ b/crates/ruma-client-api/src/tag/delete_tag.rs @@ -9,7 +9,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -24,18 +24,18 @@ pub mod v3 { /// Request type for the `delete_tag` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose tag will be deleted. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The tagged room. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The name of the tag to delete. #[ruma_api(path)] - pub tag: &'a str, + pub tag: String, } /// Response type for the `delete_tag` endpoint. @@ -43,9 +43,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID, room ID and tag - pub fn new(user_id: &'a UserId, room_id: &'a RoomId, tag: &'a str) -> Self { + pub fn new(user_id: OwnedUserId, room_id: OwnedRoomId, tag: String) -> Self { Self { user_id, room_id, tag } } } diff --git a/crates/ruma-client-api/src/tag/get_tags.rs b/crates/ruma-client-api/src/tag/get_tags.rs index 1a0e4128..287eb302 100644 --- a/crates/ruma-client-api/src/tag/get_tags.rs +++ b/crates/ruma-client-api/src/tag/get_tags.rs @@ -10,7 +10,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, events::tag::Tags, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -25,14 +25,14 @@ pub mod v3 { /// Request type for the `get_tags` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The user whose tags will be retrieved. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The room from which tags will be retrieved. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, } /// Response type for the `get_tags` endpoint. @@ -42,9 +42,9 @@ pub mod v3 { pub tags: Tags, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID and room ID. - pub fn new(user_id: &'a UserId, room_id: &'a RoomId) -> Self { + pub fn new(user_id: OwnedUserId, room_id: OwnedRoomId) -> Self { Self { user_id, room_id } } } diff --git a/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs index af848d04..07b22093 100644 --- a/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `get_location_for_protocol` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The protocol used to communicate to the third party network. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, /// One or more custom fields to help identify the third party location. // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). @@ -46,9 +46,9 @@ pub mod v3 { pub locations: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol, fields: BTreeMap::new() } } } diff --git a/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs b/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs index af53ff96..05ab258e 100644 --- a/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs +++ b/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs @@ -11,7 +11,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, thirdparty::Location, - RoomAliasId, + OwnedRoomAliasId, }; const METADATA: Metadata = metadata! { @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `get_location_for_room_alias` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The Matrix room alias to look up. #[ruma_api(query)] - pub alias: &'a RoomAliasId, + pub alias: OwnedRoomAliasId, } /// Response type for the `get_location_for_room_alias` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { pub locations: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias ID. - pub fn new(alias: &'a RoomAliasId) -> Self { + pub fn new(alias: OwnedRoomAliasId) -> Self { Self { alias } } } diff --git a/crates/ruma-client-api/src/thirdparty/get_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_protocol.rs index aa34261f..90d4da60 100644 --- a/crates/ruma-client-api/src/thirdparty/get_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_protocol.rs @@ -25,10 +25,10 @@ pub mod v3 { /// Request type for the `get_protocol` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The name of the protocol. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, } /// Response type for the `get_protocol` endpoint. @@ -39,9 +39,9 @@ pub mod v3 { pub protocol: Protocol, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol name. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol } } } diff --git a/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs index 1ce41199..02323f95 100644 --- a/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs @@ -27,10 +27,10 @@ pub mod v3 { /// Request type for the `get_user_for_protocol` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The protocol used to communicate to the third party network. #[ruma_api(path)] - pub protocol: &'a str, + pub protocol: String, /// One or more custom fields that are passed to the AS to help identify the user. // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). @@ -46,9 +46,9 @@ pub mod v3 { pub users: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given protocol. - pub fn new(protocol: &'a str) -> Self { + pub fn new(protocol: String) -> Self { Self { protocol, fields: BTreeMap::new() } } } diff --git a/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs b/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs index 4fda8437..ff453b4d 100644 --- a/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs +++ b/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs @@ -11,7 +11,7 @@ pub mod v3 { api::{request, response, Metadata}, metadata, thirdparty::User, - UserId, + OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -26,10 +26,10 @@ pub mod v3 { /// Request type for the `get_user_for_user_id` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The Matrix User ID to look up. #[ruma_api(query)] - pub userid: &'a UserId, + pub userid: OwnedUserId, } /// Response type for the `get_user_for_user_id` endpoint. @@ -40,9 +40,9 @@ pub mod v3 { pub users: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID. - pub fn new(userid: &'a UserId) -> Self { + pub fn new(userid: OwnedUserId) -> Self { Self { userid } } } diff --git a/crates/ruma-client-api/src/threads/get_threads.rs b/crates/ruma-client-api/src/threads/get_threads.rs index 5996b933..2c517318 100644 --- a/crates/ruma-client-api/src/threads/get_threads.rs +++ b/crates/ruma-client-api/src/threads/get_threads.rs @@ -13,7 +13,7 @@ pub mod v1 { events::AnyTimelineEvent, metadata, serde::{Raw, StringEnum}, - RoomId, + OwnedRoomId, }; use crate::PrivOwnedStr; @@ -30,17 +30,17 @@ pub mod v1 { /// Request type for the `get_thread_roots` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room ID where the thread roots are located. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The pagination token to start returning results from. /// /// If `None`, results start at the most recent topological event visible to the user. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub from: Option<&'a str>, + pub from: Option, /// Which thread roots are of interest to the caller. #[serde(skip_serializing_if = "ruma_common::serde::is_default")] @@ -72,9 +72,9 @@ pub mod v1 { pub next_batch: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, from: None, include: IncludeThreads::default(), limit: None } } } diff --git a/crates/ruma-client-api/src/to_device/send_event_to_device.rs b/crates/ruma-client-api/src/to_device/send_event_to_device.rs index 3c3e0ecb..2e6d9dbd 100644 --- a/crates/ruma-client-api/src/to_device/send_event_to_device.rs +++ b/crates/ruma-client-api/src/to_device/send_event_to_device.rs @@ -15,7 +15,7 @@ pub mod v3 { metadata, serde::Raw, to_device::DeviceIdOrAllDevices, - OwnedUserId, TransactionId, + OwnedTransactionId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -30,10 +30,10 @@ pub mod v3 { /// Request type for the `send_event_to_device` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// Type of event being sent to each device. #[ruma_api(path)] - pub event_type: &'a str, + pub event_type: String, /// The transaction ID for this event. /// @@ -45,7 +45,7 @@ pub mod v3 { /// /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens #[ruma_api(path)] - pub txn_id: &'a TransactionId, + pub txn_id: OwnedTransactionId, /// Messages to send. /// @@ -59,9 +59,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given event type, transaction ID and raw messages. - pub fn new_raw(event_type: &'a str, txn_id: &'a TransactionId, messages: Messages) -> Self { + pub fn new_raw(event_type: String, txn_id: OwnedTransactionId, messages: Messages) -> Self { Self { event_type, txn_id, messages } } } diff --git a/crates/ruma-client-api/src/typing/create_typing_event.rs b/crates/ruma-client-api/src/typing/create_typing_event.rs index f95b4a30..679aa692 100644 --- a/crates/ruma-client-api/src/typing/create_typing_event.rs +++ b/crates/ruma-client-api/src/typing/create_typing_event.rs @@ -11,7 +11,7 @@ pub mod v3 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; use serde::{de::Error, Deserialize, Deserializer, Serialize}; @@ -27,14 +27,14 @@ pub mod v3 { /// Request type for the `create_typing_event` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The room in which the user is typing. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user who has started to type. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// Whether the user is typing within a length of time or not. #[serde(flatten)] @@ -46,9 +46,9 @@ pub mod v3 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user ID, room ID and typing state. - pub fn new(user_id: &'a UserId, room_id: &'a RoomId, state: Typing) -> Self { + pub fn new(user_id: OwnedUserId, room_id: OwnedRoomId, state: Typing) -> Self { Self { user_id, room_id, state } } } diff --git a/crates/ruma-client-api/src/uiaa.rs b/crates/ruma-client-api/src/uiaa.rs index 374594da..6e2ee6e4 100644 --- a/crates/ruma-client-api/src/uiaa.rs +++ b/crates/ruma-client-api/src/uiaa.rs @@ -7,9 +7,9 @@ use std::{borrow::Cow, fmt}; use bytes::BufMut; use ruma_common::{ api::{error::IntoHttpError, EndpointError, OutgoingResponse}, - serde::{from_raw_json_value, Incoming, JsonObject, StringEnum}, + serde::{from_raw_json_value, JsonObject, StringEnum}, thirdparty::Medium, - ClientSecret, OwnedSessionId, OwnedUserId, UserId, + ClientSecret, OwnedSessionId, OwnedUserId, }; use serde::{ de::{self, DeserializeOwned}, @@ -28,142 +28,46 @@ pub mod get_uiaa_fallback_page; mod user_serde; /// Information for one authentication stage. -/// -/// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`] -/// and then call [`IncomingAuthData::to_outgoing`] on it. -#[derive(Clone, Incoming, Serialize)] +#[derive(Clone, Serialize)] #[non_exhaustive] -#[incoming_derive(!Debug, !Deserialize)] #[serde(untagged)] -pub enum AuthData<'a> { +pub enum AuthData { /// Password-based authentication (`m.login.password`). - Password(Password<'a>), + Password(Password), /// Google ReCaptcha 2.0 authentication (`m.login.recaptcha`). - ReCaptcha(ReCaptcha<'a>), + ReCaptcha(ReCaptcha), /// Email-based authentication (`m.login.email.identity`). - EmailIdentity(EmailIdentity<'a>), + EmailIdentity(EmailIdentity), /// Phone number-based authentication (`m.login.msisdn`). - Msisdn(Msisdn<'a>), + Msisdn(Msisdn), /// Dummy authentication (`m.login.dummy`). - Dummy(Dummy<'a>), + Dummy(Dummy), /// Registration token-based authentication (`m.login.registration_token`). - RegistrationToken(RegistrationToken<'a>), + RegistrationToken(RegistrationToken), /// Fallback acknowledgement. - FallbackAcknowledgement(FallbackAcknowledgement<'a>), + FallbackAcknowledgement(FallbackAcknowledgement), #[doc(hidden)] - _Custom(CustomAuthData<'a>), + _Custom(CustomAuthData), } -impl<'a> AuthData<'a> { - /// Creates a new `AuthData::FallbackAcknowledgement` with the given session key. - pub fn fallback_acknowledgement(session: &'a str) -> Self { - Self::FallbackAcknowledgement(FallbackAcknowledgement::new(session)) - } - - /// Returns the value of the `type` field, if it exists. - pub fn auth_type(&self) -> Option { - match self { - Self::Password(_) => Some(AuthType::Password), - Self::ReCaptcha(_) => Some(AuthType::ReCaptcha), - Self::EmailIdentity(_) => Some(AuthType::EmailIdentity), - Self::Msisdn(_) => Some(AuthType::Msisdn), - Self::Dummy(_) => Some(AuthType::Dummy), - Self::RegistrationToken(_) => Some(AuthType::RegistrationToken), - Self::FallbackAcknowledgement(_) => None, - Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.into()))), - } - } - - /// Returns the value of the `session` field, if it exists. - pub fn session(&self) -> Option<&'a str> { - match self { - Self::Password(x) => x.session, - Self::ReCaptcha(x) => x.session, - Self::EmailIdentity(x) => x.session, - Self::Msisdn(x) => x.session, - Self::Dummy(x) => x.session, - Self::RegistrationToken(x) => x.session, - Self::FallbackAcknowledgement(x) => Some(x.session), - Self::_Custom(x) => x.session, - } - } - - /// Returns the associated data. +impl AuthData { + /// Creates a new `AuthData` with the given `auth_type` string, session and data. /// - /// The returned JSON object won't contain the `type` and `session` fields, use - /// [`.auth_type()`][Self::auth_type] / [`.session()`](Self::session) to access those. - /// - /// Prefer to use the public variants of `AuthData` where possible; this method is meant to be - /// used for custom auth types only. - pub fn data(&self) -> Cow<'_, JsonObject> { - fn serialize(obj: T) -> JsonObject { - match serde_json::to_value(obj).expect("auth data serialization to succeed") { - JsonValue::Object(obj) => obj, - _ => panic!("all auth data variants must serialize to objects"), - } - } - - match self { - Self::Password(x) => Cow::Owned(serialize(Password { - identifier: x.identifier.clone(), - password: x.password, - session: None, - })), - Self::ReCaptcha(x) => { - Cow::Owned(serialize(ReCaptcha { response: x.response, session: None })) - } - Self::EmailIdentity(x) => Cow::Owned(serialize(EmailIdentity { - thirdparty_id_creds: x.thirdparty_id_creds, - session: None, - })), - Self::Msisdn(x) => Cow::Owned(serialize(Msisdn { - thirdparty_id_creds: x.thirdparty_id_creds, - session: None, - })), - Self::RegistrationToken(x) => { - Cow::Owned(serialize(RegistrationToken { token: x.token, session: None })) - } - // Dummy and fallback acknowledgement have no associated data - Self::Dummy(_) | Self::FallbackAcknowledgement(_) => Cow::Owned(JsonObject::default()), - Self::_Custom(c) => Cow::Borrowed(c.extra), - } - } -} - -impl fmt::Debug for AuthData<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // Print `Password { .. }` instead of `Password(Password { .. })` - match self { - Self::Password(inner) => inner.fmt(f), - Self::ReCaptcha(inner) => inner.fmt(f), - Self::EmailIdentity(inner) => inner.fmt(f), - Self::Msisdn(inner) => inner.fmt(f), - Self::Dummy(inner) => inner.fmt(f), - Self::RegistrationToken(inner) => inner.fmt(f), - Self::FallbackAcknowledgement(inner) => inner.fmt(f), - Self::_Custom(inner) => inner.fmt(f), - } - } -} - -impl IncomingAuthData { - /// Creates a new `IncomingAuthData` with the given `auth_type` string, session and data. - /// - /// Prefer to use the public variants of `IncomingAuthData` where possible; this constructor is - /// meant be used for unsupported authentication types only and does not allow setting arbitrary + /// Prefer to use the public variants of `AuthData` where possible; this constructor is meant to + /// be used for unsupported authentication types only and does not allow setting arbitrary /// data for supported ones. /// /// # Errors /// /// Returns an error if the `auth_type` is known and serialization of `data` to the - /// corresponding `IncomingAuthData` variant fails. + /// corresponding `AuthData` variant fails. pub fn new( auth_type: &str, session: Option, @@ -186,14 +90,17 @@ impl IncomingAuthData { "m.login.msisdn" => Self::Msisdn(deserialize_variant(session, data)?), "m.login.dummy" => Self::Dummy(deserialize_variant(session, data)?), "m.registration_token" => Self::RegistrationToken(deserialize_variant(session, data)?), - _ => Self::_Custom(IncomingCustomAuthData { - auth_type: auth_type.into(), - session, - extra: data, - }), + _ => { + Self::_Custom(CustomAuthData { auth_type: auth_type.into(), session, extra: data }) + } }) } + /// Creates a new `AuthData::FallbackAcknowledgement` with the given session key. + pub fn fallback_acknowledgement(session: String) -> Self { + Self::FallbackAcknowledgement(FallbackAcknowledgement::new(session)) + } + /// Returns the value of the `type` field, if it exists. pub fn auth_type(&self) -> Option { match self { @@ -239,50 +146,32 @@ impl IncomingAuthData { match self { Self::Password(x) => Cow::Owned(serialize(Password { - identifier: x.identifier.to_outgoing(), - password: &x.password, + identifier: x.identifier.clone(), + password: x.password.clone(), session: None, })), Self::ReCaptcha(x) => { - Cow::Owned(serialize(ReCaptcha { response: &x.response, session: None })) + Cow::Owned(serialize(ReCaptcha { response: x.response.clone(), session: None })) } Self::EmailIdentity(x) => Cow::Owned(serialize(EmailIdentity { - thirdparty_id_creds: &x.thirdparty_id_creds, + thirdparty_id_creds: x.thirdparty_id_creds.clone(), session: None, })), Self::Msisdn(x) => Cow::Owned(serialize(Msisdn { - thirdparty_id_creds: &x.thirdparty_id_creds, + thirdparty_id_creds: x.thirdparty_id_creds.clone(), session: None, })), Self::RegistrationToken(x) => { - Cow::Owned(serialize(RegistrationToken { token: &x.token, session: None })) + Cow::Owned(serialize(RegistrationToken { token: x.token.clone(), session: None })) } // Dummy and fallback acknowledgement have no associated data Self::Dummy(_) | Self::FallbackAcknowledgement(_) => Cow::Owned(JsonObject::default()), Self::_Custom(c) => Cow::Borrowed(&c.extra), } } - - /// Convert `IncomingAuthData` to `AuthData`. - pub fn to_outgoing(&self) -> AuthData<'_> { - match self { - Self::Password(a) => AuthData::Password(a.to_outgoing()), - Self::ReCaptcha(a) => AuthData::ReCaptcha(a.to_outgoing()), - Self::EmailIdentity(a) => AuthData::EmailIdentity(a.to_outgoing()), - Self::Msisdn(a) => AuthData::Msisdn(a.to_outgoing()), - Self::Dummy(a) => AuthData::Dummy(a.to_outgoing()), - Self::RegistrationToken(a) => AuthData::RegistrationToken(a.to_outgoing()), - Self::FallbackAcknowledgement(a) => AuthData::FallbackAcknowledgement(a.to_outgoing()), - Self::_Custom(a) => AuthData::_Custom(CustomAuthData { - auth_type: &a.auth_type, - session: a.session.as_deref(), - extra: &a.extra, - }), - } - } } -impl fmt::Debug for IncomingAuthData { +impl fmt::Debug for AuthData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Print `Password { .. }` instead of `Password(Password { .. })` match self { @@ -298,7 +187,7 @@ impl fmt::Debug for IncomingAuthData { } } -impl<'de> Deserialize<'de> for IncomingAuthData { +impl<'de> Deserialize<'de> for AuthData { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -372,29 +261,28 @@ pub enum AuthType { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#password-based -#[derive(Clone, Incoming, Serialize)] +#[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(!Debug)] #[serde(tag = "type", rename = "m.login.password")] -pub struct Password<'a> { +pub struct Password { /// One of the user's identifiers. - pub identifier: UserIdentifier<'a>, + pub identifier: UserIdentifier, /// The plaintext password. - pub password: &'a str, + pub password: String, /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, + pub session: Option, } -impl<'a> Password<'a> { +impl Password { /// Creates a new `Password` with the given identifier and password. - pub fn new(identifier: UserIdentifier<'a>, password: &'a str) -> Self { + pub fn new(identifier: UserIdentifier, password: String) -> Self { Self { identifier, password, session: None } } } -impl fmt::Debug for Password<'_> { +impl fmt::Debug for Password { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { identifier, password: _, session } = self; f.debug_struct("Password") @@ -404,97 +292,51 @@ impl fmt::Debug for Password<'_> { } } -impl IncomingPassword { - /// Convert `IncomingPassword` to `Password`. - fn to_outgoing(&self) -> Password<'_> { - Password { - identifier: self.identifier.to_outgoing(), - password: &self.password, - session: self.session.as_deref(), - } - } -} - -impl fmt::Debug for IncomingPassword { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { identifier, password: _, session } = self; - f.debug_struct("IncomingPassword") - .field("identifier", identifier) - .field("session", session) - .finish_non_exhaustive() - } -} - /// Data for ReCaptcha UIAA flow. /// /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#google-recaptcha -#[derive(Clone, Incoming, Serialize)] +#[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(!Debug)] #[serde(tag = "type", rename = "m.login.recaptcha")] -pub struct ReCaptcha<'a> { +pub struct ReCaptcha { /// The captcha response. - pub response: &'a str, + pub response: String, /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, + pub session: Option, } -impl<'a> ReCaptcha<'a> { +impl ReCaptcha { /// Creates a new `ReCaptcha` with the given response string. - pub fn new(response: &'a str) -> Self { + pub fn new(response: String) -> Self { Self { response, session: None } } } -impl fmt::Debug for ReCaptcha<'_> { +impl fmt::Debug for ReCaptcha { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { response: _, session } = self; f.debug_struct("ReCaptcha").field("session", session).finish_non_exhaustive() } } -impl IncomingReCaptcha { - /// Convert `IncomingReCaptcha` to `ReCaptcha`. - fn to_outgoing(&self) -> ReCaptcha<'_> { - ReCaptcha { response: &self.response, session: self.session.as_deref() } - } -} - -impl fmt::Debug for IncomingReCaptcha { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { response: _, session } = self; - f.debug_struct("IncomingReCaptcha").field("session", session).finish_non_exhaustive() - } -} - /// Data for Email-based UIAA flow. /// /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#email-based-identity--homeserver -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.email.identity")] -pub struct EmailIdentity<'a> { +pub struct EmailIdentity { /// Thirdparty identifier credentials. #[serde(rename = "threepid_creds")] - pub thirdparty_id_creds: &'a ThirdpartyIdCredentials, + pub thirdparty_id_creds: ThirdpartyIdCredentials, /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, -} - -impl IncomingEmailIdentity { - /// Convert `IncomingEmailIdentity` to `EmailIdentity`. - fn to_outgoing(&self) -> EmailIdentity<'_> { - EmailIdentity { - thirdparty_id_creds: &self.thirdparty_id_creds, - session: self.session.as_deref(), - } - } + pub session: Option, } /// Data for phone number-based UIAA flow. @@ -502,23 +344,16 @@ impl IncomingEmailIdentity { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#phone-numbermsisdn-based-identity--homeserver -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.msisdn")] -pub struct Msisdn<'a> { +pub struct Msisdn { /// Thirdparty identifier credentials. #[serde(rename = "threepid_creds")] - pub thirdparty_id_creds: &'a ThirdpartyIdCredentials, + pub thirdparty_id_creds: ThirdpartyIdCredentials, /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, -} - -impl IncomingMsisdn { - /// Convert `IncomingMsisdn` to `Msisdn`. - fn to_outgoing(&self) -> Msisdn<'_> { - Msisdn { thirdparty_id_creds: &self.thirdparty_id_creds, session: self.session.as_deref() } - } + pub session: Option, } /// Data for dummy UIAA flow. @@ -526,126 +361,74 @@ impl IncomingMsisdn { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#dummy-auth -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.dummy")] -pub struct Dummy<'a> { +pub struct Dummy { /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, + pub session: Option, } -impl Dummy<'_> { +impl Dummy { /// Creates an empty `Dummy`. pub fn new() -> Self { Self::default() } } -impl IncomingDummy { - /// Convert from `IncomingDummy` to `Dummy`. - fn to_outgoing(&self) -> Dummy<'_> { - Dummy { session: self.session.as_deref() } - } -} - /// Data for registration token-based UIAA flow. /// /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#token-authenticated-registration -#[derive(Clone, Incoming, Serialize)] +#[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(!Debug)] #[serde(tag = "type", rename = "m.login.registration_token")] -pub struct RegistrationToken<'a> { +pub struct RegistrationToken { /// The registration token. - pub token: &'a str, + pub token: String, /// The value of the session key given by the homeserver, if any. - pub session: Option<&'a str>, + pub session: Option, } -impl<'a> RegistrationToken<'a> { +impl RegistrationToken { /// Creates a new `RegistrationToken` with the given token. - pub fn new(token: &'a str) -> Self { + pub fn new(token: String) -> Self { Self { token, session: None } } } -impl fmt::Debug for RegistrationToken<'_> { +impl fmt::Debug for RegistrationToken { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { token: _, session } = self; f.debug_struct("RegistrationToken").field("session", session).finish_non_exhaustive() } } -impl IncomingRegistrationToken { - /// Convert from `IncomingRegistrationToken` to `RegistrationToken`. - fn to_outgoing(&self) -> RegistrationToken<'_> { - RegistrationToken { token: &self.token, session: self.session.as_deref() } - } -} - -impl fmt::Debug for IncomingRegistrationToken { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { token: _, session } = self; - f.debug_struct("IncomingRegistrationToken") - .field("session", session) - .finish_non_exhaustive() - } -} - /// Data for UIAA fallback acknowledgement. /// /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.4/client-server-api/#fallback -#[derive(Clone, Debug, Incoming, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct FallbackAcknowledgement<'a> { +pub struct FallbackAcknowledgement { /// The value of the session key given by the homeserver. - pub session: &'a str, + pub session: String, } -impl<'a> FallbackAcknowledgement<'a> { +impl FallbackAcknowledgement { /// Creates a new `FallbackAcknowledgement` with the given session key. - pub fn new(session: &'a str) -> Self { + pub fn new(session: String) -> Self { Self { session } } } -impl IncomingFallbackAcknowledgement { - /// Convert from `IncomingFallbackAcknowledgement` to `FallbackAcknowledgement`. - fn to_outgoing(&self) -> FallbackAcknowledgement<'_> { - FallbackAcknowledgement { session: &self.session } - } -} - #[doc(hidden)] -#[derive(Clone, Serialize)] +#[derive(Clone, Deserialize, Serialize)] #[non_exhaustive] -pub struct CustomAuthData<'a> { - #[serde(rename = "type")] - auth_type: &'a str, - session: Option<&'a str>, - #[serde(flatten)] - extra: &'a JsonObject, -} - -impl fmt::Debug for CustomAuthData<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { auth_type, session, extra: _ } = self; - f.debug_struct("CustomAuthData") - .field("auth_type", auth_type) - .field("session", session) - .finish_non_exhaustive() - } -} - -#[doc(hidden)] -#[derive(Clone, Deserialize)] -#[non_exhaustive] -pub struct IncomingCustomAuthData { +pub struct CustomAuthData { #[serde(rename = "type")] auth_type: String, session: Option, @@ -653,7 +436,7 @@ pub struct IncomingCustomAuthData { extra: JsonObject, } -impl fmt::Debug for IncomingCustomAuthData { +impl fmt::Debug for CustomAuthData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { auth_type, session, extra: _ } = self; f.debug_struct("CustomAuthData") @@ -664,18 +447,17 @@ impl fmt::Debug for IncomingCustomAuthData { } /// Identification information for the user. -#[derive(Clone, Debug, PartialEq, Eq, Incoming)] -#[incoming_derive(!Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq)] #[allow(clippy::exhaustive_enums)] -pub enum UserIdentifier<'a> { +pub enum UserIdentifier { /// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier' /// field). - UserIdOrLocalpart(&'a str), + UserIdOrLocalpart(String), /// An email address. Email { /// The email address. - address: &'a str, + address: String, }, /// A phone number in the MSISDN format. @@ -683,7 +465,7 @@ pub enum UserIdentifier<'a> { /// The phone number according to the [E.164] numbering plan. /// /// [E.164]: https://www.itu.int/rec/T-REC-E.164-201011-I/en - number: &'a str, + number: String, }, /// A phone number as a separate country code and phone number. @@ -695,19 +477,19 @@ pub enum UserIdentifier<'a> { /// This is a two-letter uppercase [ISO-3166-1 alpha-2] country code. /// /// [ISO-3166-1 alpha-2]: https://www.iso.org/iso-3166-country-codes.html - country: &'a str, + country: String, /// The phone number. - phone: &'a str, + phone: String, }, #[doc(hidden)] - _CustomThirdParty(CustomThirdPartyId<'a>), + _CustomThirdParty(CustomThirdPartyId), } -impl<'a> UserIdentifier<'a> { +impl UserIdentifier { /// Creates a new `UserIdentifier` from the given third party identifier. - pub fn third_party_id(medium: &'a Medium, address: &'a str) -> Self { + pub fn third_party_id(medium: Medium, address: String) -> Self { match medium { Medium::Email => Self::Email { address }, Medium::Msisdn => Self::Msisdn { number: address }, @@ -716,7 +498,7 @@ impl<'a> UserIdentifier<'a> { } /// Get this `UserIdentifier` as a third party identifier if it is one. - pub fn as_third_party_id(&self) -> Option<(&'a Medium, &'a str)> { + pub fn as_third_party_id(&self) -> Option<(&Medium, &str)> { match self { Self::Email { address } => Some((&Medium::Email, address)), Self::Msisdn { number } => Some((&Medium::Msisdn, number)), @@ -728,39 +510,24 @@ impl<'a> UserIdentifier<'a> { } } -impl<'a> From<&'a UserId> for UserIdentifier<'a> { - fn from(id: &'a UserId) -> Self { - Self::UserIdOrLocalpart(id.as_str()) +impl From for UserIdentifier { + fn from(id: OwnedUserId) -> Self { + Self::UserIdOrLocalpart(id.into()) } } -impl<'a> From<&'a OwnedUserId> for UserIdentifier<'a> { - fn from(id: &'a OwnedUserId) -> Self { - Self::UserIdOrLocalpart(id.as_str()) - } -} - -impl IncomingUserIdentifier { - pub(crate) fn to_outgoing(&self) -> UserIdentifier<'_> { - match self { - Self::UserIdOrLocalpart(id) => UserIdentifier::UserIdOrLocalpart(id), - Self::Email { address } => UserIdentifier::Email { address }, - Self::Msisdn { number } => UserIdentifier::Msisdn { number }, - Self::PhoneNumber { country, phone } => UserIdentifier::PhoneNumber { country, phone }, - Self::_CustomThirdParty(id) => UserIdentifier::_CustomThirdParty(CustomThirdPartyId { - medium: &id.medium, - address: &id.address, - }), - } +impl From<&OwnedUserId> for UserIdentifier { + fn from(id: &OwnedUserId) -> Self { + Self::UserIdOrLocalpart(id.as_str().to_owned()) } } #[doc(hidden)] #[derive(Clone, Debug, PartialEq, Eq, Serialize)] #[non_exhaustive] -pub struct CustomThirdPartyId<'a> { - medium: &'a Medium, - address: &'a str, +pub struct CustomThirdPartyId { + medium: Medium, + address: String, } #[doc(hidden)] diff --git a/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs b/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs index 38fa1d14..dc3d3fcb 100644 --- a/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs +++ b/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs @@ -25,14 +25,14 @@ pub mod v3 { /// Request type for the `authorize_fallback` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The type name ("m.login.dummy", etc.) of the uiaa stage to get a fallback page for. #[ruma_api(path)] - pub auth_type: &'a str, + pub auth_type: String, /// The ID of the session given by the homeserver. #[ruma_api(query)] - pub session: &'a str, + pub session: String, } /// Response type for the `authorize_fallback` endpoint. @@ -48,9 +48,9 @@ pub mod v3 { pub body: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given auth type and session ID. - pub fn new(auth_type: &'a str, session: &'a str) -> Self { + pub fn new(auth_type: String, session: String) -> Self { Self { auth_type, session } } } diff --git a/crates/ruma-client-api/src/uiaa/user_serde.rs b/crates/ruma-client-api/src/uiaa/user_serde.rs index 84ece28d..7402cbeb 100644 --- a/crates/ruma-client-api/src/uiaa/user_serde.rs +++ b/crates/ruma-client-api/src/uiaa/user_serde.rs @@ -5,11 +5,9 @@ use ruma_common::{serde::from_raw_json_value, thirdparty::Medium}; use serde::{de, ser::SerializeStruct, Deserialize, Deserializer, Serialize}; use serde_json::value::RawValue as RawJsonValue; -use super::{ - CustomThirdPartyId, IncomingCustomThirdPartyId, IncomingUserIdentifier, UserIdentifier, -}; +use super::{CustomThirdPartyId, UserIdentifier}; -impl<'a> Serialize for UserIdentifier<'a> { +impl Serialize for UserIdentifier { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -50,7 +48,7 @@ impl<'a> Serialize for UserIdentifier<'a> { } } -impl<'de> Deserialize<'de> for IncomingUserIdentifier { +impl<'de> Deserialize<'de> for UserIdentifier { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -97,9 +95,7 @@ impl<'de> Deserialize<'de> for IncomingUserIdentifier { match medium { Medium::Email => Ok(Self::Email { address }), Medium::Msisdn => Ok(Self::Msisdn { number: address }), - _ => { - Ok(Self::_CustomThirdParty(IncomingCustomThirdPartyId { medium, address })) - } + _ => Ok(Self::_CustomThirdParty(CustomThirdPartyId { medium, address })), } } } @@ -108,14 +104,15 @@ impl<'de> Deserialize<'de> for IncomingUserIdentifier { #[cfg(test)] mod tests { - use crate::uiaa::{IncomingUserIdentifier, UserIdentifier}; + use crate::uiaa::UserIdentifier; use assert_matches::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; #[test] fn serialize() { assert_eq!( - to_json_value(UserIdentifier::UserIdOrLocalpart("@user:notareal.hs")).unwrap(), + to_json_value(UserIdentifier::UserIdOrLocalpart("@user:notareal.hs".to_owned())) + .unwrap(), json!({ "type": "m.id.user", "user": "@user:notareal.hs", @@ -123,8 +120,11 @@ mod tests { ); assert_eq!( - to_json_value(UserIdentifier::PhoneNumber { country: "33", phone: "0102030405" }) - .unwrap(), + to_json_value(UserIdentifier::PhoneNumber { + country: "33".to_owned(), + phone: "0102030405".to_owned() + }) + .unwrap(), json!({ "type": "m.id.phone", "country": "33", @@ -133,7 +133,8 @@ mod tests { ); assert_eq!( - to_json_value(UserIdentifier::Email { address: "me@myprovider.net" }).unwrap(), + to_json_value(UserIdentifier::Email { address: "me@myprovider.net".to_owned() }) + .unwrap(), json!({ "type": "m.id.thirdparty", "medium": "email", @@ -142,7 +143,7 @@ mod tests { ); assert_eq!( - to_json_value(UserIdentifier::Msisdn { number: "330102030405" }).unwrap(), + to_json_value(UserIdentifier::Msisdn { number: "330102030405".to_owned() }).unwrap(), json!({ "type": "m.id.thirdparty", "medium": "msisdn", @@ -151,7 +152,8 @@ mod tests { ); assert_eq!( - to_json_value(UserIdentifier::third_party_id(&"robot".into(), "01001110")).unwrap(), + to_json_value(UserIdentifier::third_party_id("robot".into(), "01001110".to_owned())) + .unwrap(), json!({ "type": "m.id.thirdparty", "medium": "robot", @@ -168,7 +170,7 @@ mod tests { }); let user = assert_matches!( from_json_value(json), - Ok(IncomingUserIdentifier::UserIdOrLocalpart(user)) => user + Ok(UserIdentifier::UserIdOrLocalpart(user)) => user ); assert_eq!(user, "@user:notareal.hs"); @@ -179,7 +181,7 @@ mod tests { }); let (country, phone) = assert_matches!( from_json_value(json), - Ok(IncomingUserIdentifier::PhoneNumber { country, phone }) => (country, phone) + Ok(UserIdentifier::PhoneNumber { country, phone }) => (country, phone) ); assert_eq!(country, "33"); assert_eq!(phone, "0102030405"); @@ -191,7 +193,7 @@ mod tests { }); let address = assert_matches!( from_json_value(json), - Ok(IncomingUserIdentifier::Email { address }) => address + Ok(UserIdentifier::Email { address }) => address ); assert_eq!(address, "me@myprovider.net"); @@ -202,7 +204,7 @@ mod tests { }); let number = assert_matches!( from_json_value(json), - Ok(IncomingUserIdentifier::Msisdn { number }) => number + Ok(UserIdentifier::Msisdn { number }) => number ); assert_eq!(number, "330102030405"); @@ -211,8 +213,8 @@ mod tests { "medium": "robot", "address": "01110010", }); - let id = from_json_value::(json).unwrap(); - let (medium, address) = id.to_outgoing().as_third_party_id().unwrap(); + let id = from_json_value::(json).unwrap(); + let (medium, address) = id.as_third_party_id().unwrap(); assert_eq!(medium.as_str(), "robot"); assert_eq!(address, "01110010"); } diff --git a/crates/ruma-client-api/src/user_directory/search_users.rs b/crates/ruma-client-api/src/user_directory/search_users.rs index c272caa3..26940292 100644 --- a/crates/ruma-client-api/src/user_directory/search_users.rs +++ b/crates/ruma-client-api/src/user_directory/search_users.rs @@ -27,9 +27,9 @@ pub mod v3 { /// Request type for the `search_users` endpoint. #[request(error = crate::Error)] - pub struct Request<'a> { + pub struct Request { /// The term to search for. - pub search_term: &'a str, + pub search_term: String, /// The maximum number of results to return. /// @@ -56,9 +56,9 @@ pub mod v3 { pub limited: bool, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given search term. - pub fn new(search_term: &'a str) -> Self { + pub fn new(search_term: String) -> Self { Self { search_term, limit: default_limit(), language: None } } } diff --git a/crates/ruma-client-api/tests/uiaa.rs b/crates/ruma-client-api/tests/uiaa.rs index c34a2e20..5c15c92a 100644 --- a/crates/ruma-client-api/tests/uiaa.rs +++ b/crates/ruma-client-api/tests/uiaa.rs @@ -4,10 +4,7 @@ use assert_matches::assert_matches; use assign::assign; use ruma_client_api::{ error::ErrorKind, - uiaa::{ - self, AuthData, AuthFlow, AuthType, IncomingAuthData, IncomingUserIdentifier, UiaaInfo, - UiaaResponse, - }, + uiaa::{self, AuthData, AuthFlow, AuthType, UiaaInfo, UiaaResponse, UserIdentifier}, }; use ruma_common::api::{EndpointError, OutgoingResponse}; use serde_json::{ @@ -23,16 +20,17 @@ fn deserialize_user_identifier() { "user": "cheeky_monkey" })) .unwrap(), - IncomingUserIdentifier::UserIdOrLocalpart(id) => id + UserIdentifier::UserIdOrLocalpart(id) => id ); assert_eq!(id, "cheeky_monkey"); } #[test] fn serialize_auth_data_registration_token() { - let auth_data = AuthData::RegistrationToken( - assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }), - ); + let auth_data = + AuthData::RegistrationToken(assign!(uiaa::RegistrationToken::new("mytoken".to_owned()), { + session: Some("session".to_owned()), + })); assert_eq!( to_json_value(auth_data).unwrap(), @@ -54,7 +52,7 @@ fn deserialize_auth_data_registration_token() { let data = assert_matches!( from_json_value(json), - Ok(IncomingAuthData::RegistrationToken(data)) => data + Ok(AuthData::RegistrationToken(data)) => data ); assert_eq!(data.token, "mytoken"); assert_eq!(data.session.as_deref(), Some("session")); @@ -62,7 +60,8 @@ fn deserialize_auth_data_registration_token() { #[test] fn serialize_auth_data_fallback() { - let auth_data = AuthData::FallbackAcknowledgement(uiaa::FallbackAcknowledgement::new("ZXY000")); + let auth_data = + AuthData::FallbackAcknowledgement(uiaa::FallbackAcknowledgement::new("ZXY000".to_owned())); assert_eq!(json!({ "session": "ZXY000" }), to_json_value(auth_data).unwrap()); } @@ -73,7 +72,7 @@ fn deserialize_auth_data_fallback() { let data = assert_matches!( from_json_value(json).unwrap(), - IncomingAuthData::FallbackAcknowledgement(data) => data + AuthData::FallbackAcknowledgement(data) => data ); assert_eq!(data.session, "opaque_session_id"); } diff --git a/crates/ruma-client/src/client.rs b/crates/ruma-client/src/client.rs index f0f6b33a..db12209b 100644 --- a/crates/ruma-client/src/client.rs +++ b/crates/ruma-client/src/client.rs @@ -118,13 +118,15 @@ impl Client { device_id: Option<&DeviceId>, initial_device_display_name: Option<&str>, ) -> Result> { + let login_info = LoginInfo::Password(login::v3::Password::new( + UserIdentifier::UserIdOrLocalpart(user.to_owned()), + password.to_owned(), + )); let response = self - .send_request(assign!(login::v3::Request::new( - LoginInfo::Password(login::v3::Password::new(UserIdentifier::UserIdOrLocalpart(user), password))), { - device_id, - initial_device_display_name, - } - )) + .send_request(assign!(login::v3::Request::new(login_info), { + device_id: device_id.map(ToOwned::to_owned), + initial_device_display_name: initial_device_display_name.map(ToOwned::to_owned), + })) .await?; *self.0.access_token.lock().unwrap() = Some(response.access_token.clone()); @@ -162,7 +164,8 @@ impl Client { ) -> Result> { let response = self .send_request(assign!(register::v3::Request::new(), { - username, password: Some(password) + username: username.map(ToOwned::to_owned), + password: Some(password.to_owned()) })) .await?; @@ -190,7 +193,7 @@ impl Client { /// let mut sync_stream = Box::pin(client.sync( /// None, /// next_batch_token, - /// &PresenceState::Online, + /// PresenceState::Online, /// Some(Duration::from_secs(30)), /// )); /// while let Some(response) = sync_stream.try_next().await? { @@ -199,21 +202,21 @@ impl Client { /// # Result::<(), ruma_client::Error<_, _>>::Ok(()) /// # }; /// ``` - pub fn sync<'a>( - &'a self, - filter: Option<&'a sync_events::v3::Filter<'a>>, + pub fn sync( + &self, + filter: Option, mut since: String, - set_presence: &'a PresenceState, + set_presence: PresenceState, timeout: Option, ) -> impl Stream>> - + 'a { + + '_ { try_stream! { loop { let response = self .send_request(assign!(sync_events::v3::Request::new(), { - filter, - since: Some(&since), - set_presence, + filter: filter.clone(), + since: Some(since.clone()), + set_presence: set_presence.clone(), timeout, })) .await?; diff --git a/crates/ruma-client/src/lib.rs b/crates/ruma-client/src/lib.rs index fae2ce52..2263f8b4 100644 --- a/crates/ruma-client/src/lib.rs +++ b/crates/ruma-client/src/lib.rs @@ -70,7 +70,9 @@ //! use ruma_common::{api::MatrixVersion, room_alias_id, room_id}; //! //! let response = client -//! .send_request(get_alias::v3::Request::new(room_alias_id!("#example_room:example.com"))) +//! .send_request(get_alias::v3::Request::new( +//! room_alias_id!("#example_room:example.com").to_owned(), +//! )) //! .await?; //! //! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com")); diff --git a/crates/ruma-common/src/api.rs b/crates/ruma-common/src/api.rs index f23d2edb..d659fe65 100644 --- a/crates/ruma-common/src/api.rs +++ b/crates/ruma-common/src/api.rs @@ -56,13 +56,13 @@ use crate::UserId; /// object). /// * `#[ruma_api(raw_body)]`: Like `body` in that the field annotated with it represents the /// entire request body, but this attribute is for endpoints where the body can be anything, -/// not just JSON. The field type must be `&[u8]`. +/// not just JSON. The field type must be `Vec`. /// /// ## Examples /// /// ``` /// pub mod do_a_thing { -/// use ruma_common::{api::request, RoomId}; +/// use ruma_common::{api::request, OwnedRoomId}; /// # use ruma_common::{ /// # api::{response, Metadata}, /// # metadata, @@ -79,12 +79,12 @@ use crate::UserId; /// # }; /// /// #[request] -/// pub struct Request<'a> { +/// pub struct Request { /// #[ruma_api(path)] -/// pub room_id: &'a RoomId, +/// pub room_id: OwnedRoomId, /// /// #[ruma_api(query)] -/// pub bar: &'a str, +/// pub bar: String, /// /// #[serde(default)] /// pub foo: String, @@ -115,15 +115,15 @@ use crate::UserId; /// # }; /// /// #[request] -/// pub struct Request<'a> { +/// pub struct Request { /// #[ruma_api(path)] -/// pub file_name: &'a str, +/// pub file_name: String, /// /// #[ruma_api(header = CONTENT_TYPE)] /// pub content_type: String, /// /// #[ruma_api(raw_body)] -/// pub file: &'a [u8], +/// pub file: Vec, /// } /// /// // #[response] diff --git a/crates/ruma-common/src/directory.rs b/crates/ruma-common/src/directory.rs index 2ff30ca5..b31ba7a2 100644 --- a/crates/ruma-common/src/directory.rs +++ b/crates/ruma-common/src/directory.rs @@ -7,9 +7,7 @@ mod filter_room_type_serde; mod room_network_serde; use crate::{ - room::RoomType, - serde::{Incoming, StringEnum}, - OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, PrivOwnedStr, + room::RoomType, serde::StringEnum, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, PrivOwnedStr, }; /// A chunk of a room list response, describing one room. @@ -112,13 +110,12 @@ impl From for PublicRoomsChunk { } /// A filter for public rooms lists -#[derive(Clone, Debug, Default, Incoming, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Default)] -pub struct Filter<'a> { +pub struct Filter { /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. #[serde(skip_serializing_if = "Option::is_none")] - pub generic_search_term: Option<&'a str>, + pub generic_search_term: Option, /// The room types to include in the results. /// @@ -127,7 +124,7 @@ pub struct Filter<'a> { pub room_types: Vec, } -impl Filter<'_> { +impl Filter { /// Creates an empty `Filter`. pub fn new() -> Self { Default::default() @@ -141,10 +138,9 @@ impl Filter<'_> { /// Information about which networks/protocols from application services on the /// homeserver from which to request rooms. -#[derive(Clone, Debug, Default, PartialEq, Eq, Incoming)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[incoming_derive(Clone, Default, PartialEq, Eq, !Deserialize)] -pub enum RoomNetwork<'a> { +pub enum RoomNetwork { /// Return rooms from the Matrix network. #[default] Matrix, @@ -153,7 +149,7 @@ pub enum RoomNetwork<'a> { All, /// Return rooms from a specific third party network/protocol. - ThirdParty(&'a str), + ThirdParty(String), } /// The rule used for users wishing to join a public room. @@ -228,7 +224,7 @@ mod tests { use assert_matches::assert_matches; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - use super::{Filter, IncomingFilter, IncomingRoomNetwork, RoomNetwork, RoomTypeFilter}; + use super::{Filter, RoomNetwork, RoomTypeFilter}; #[test] fn serialize_matrix_network_only() { @@ -239,10 +235,7 @@ mod tests { #[test] fn deserialize_matrix_network_only() { let json = json!({ "include_all_networks": false }); - assert_eq!( - from_json_value::(json).unwrap(), - IncomingRoomNetwork::Matrix - ); + assert_eq!(from_json_value::(json).unwrap(), RoomNetwork::Matrix); } #[test] @@ -254,10 +247,7 @@ mod tests { #[test] fn deserialize_empty_network_is_default() { let json = json!({}); - assert_eq!( - from_json_value::(json).unwrap(), - IncomingRoomNetwork::Matrix - ); + assert_eq!(from_json_value::(json).unwrap(), RoomNetwork::Matrix); } #[test] @@ -269,21 +259,21 @@ mod tests { #[test] fn deserialize_include_all_networks() { let json = json!({ "include_all_networks": true }); - assert_eq!(from_json_value::(json).unwrap(), IncomingRoomNetwork::All); + assert_eq!(from_json_value::(json).unwrap(), RoomNetwork::All); } #[test] fn serialize_third_party_network() { let json = json!({ "third_party_instance_id": "freenode" }); - assert_eq!(to_json_value(RoomNetwork::ThirdParty("freenode")).unwrap(), json); + assert_eq!(to_json_value(RoomNetwork::ThirdParty("freenode".to_owned())).unwrap(), json); } #[test] fn deserialize_third_party_network() { let json = json!({ "third_party_instance_id": "freenode" }); assert_eq!( - from_json_value::(json).unwrap(), - IncomingRoomNetwork::ThirdParty("freenode".into()) + from_json_value::(json).unwrap(), + RoomNetwork::ThirdParty("freenode".into()) ); } @@ -291,7 +281,7 @@ mod tests { fn deserialize_include_all_networks_and_third_party_exclusivity() { let json = json!({ "include_all_networks": true, "third_party_instance_id": "freenode" }); assert_eq!( - from_json_value::(json).unwrap_err().to_string().as_str(), + from_json_value::(json).unwrap_err().to_string().as_str(), "`include_all_networks = true` and `third_party_instance_id` are mutually exclusive." ); } @@ -306,7 +296,7 @@ mod tests { #[test] fn deserialize_filter_empty() { let json = json!({}); - let filter = from_json_value::(json).unwrap(); + let filter = from_json_value::(json).unwrap(); assert_eq!(filter.generic_search_term, None); assert_eq!(filter.room_types.len(), 0); } @@ -328,7 +318,7 @@ mod tests { #[test] fn deserialize_filter_room_types() { let json = json!({ "room_types": [null, "m.space", "custom_type"] }); - let filter = from_json_value::(json).unwrap(); + let filter = from_json_value::(json).unwrap(); assert_eq!(filter.room_types.len(), 3); assert_eq!(filter.room_types[0], RoomTypeFilter::Default); assert_eq!(filter.room_types[1], RoomTypeFilter::Space); diff --git a/crates/ruma-common/src/directory/room_network_serde.rs b/crates/ruma-common/src/directory/room_network_serde.rs index a1b2e643..75da81e4 100644 --- a/crates/ruma-common/src/directory/room_network_serde.rs +++ b/crates/ruma-common/src/directory/room_network_serde.rs @@ -7,9 +7,9 @@ use serde::{ }; use serde_json::Value as JsonValue; -use super::{IncomingRoomNetwork, RoomNetwork}; +use super::RoomNetwork; -impl<'a> Serialize for RoomNetwork<'a> { +impl Serialize for RoomNetwork { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -32,7 +32,7 @@ impl<'a> Serialize for RoomNetwork<'a> { } } -impl<'de> Deserialize<'de> for IncomingRoomNetwork { +impl<'de> Deserialize<'de> for RoomNetwork { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -43,7 +43,7 @@ impl<'de> Deserialize<'de> for IncomingRoomNetwork { struct RoomNetworkVisitor; impl<'de> Visitor<'de> for RoomNetworkVisitor { - type Value = IncomingRoomNetwork; + type Value = RoomNetwork; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("Network selection") @@ -72,7 +72,7 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor { if include_all_networks { if third_party_instance_id.is_none() { - Ok(IncomingRoomNetwork::All) + Ok(RoomNetwork::All) } else { Err(M::Error::custom( "`include_all_networks = true` and `third_party_instance_id` are mutually exclusive.", @@ -80,8 +80,8 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor { } } else { Ok(match third_party_instance_id { - Some(network) => IncomingRoomNetwork::ThirdParty(network), - None => IncomingRoomNetwork::Matrix, + Some(network) => RoomNetwork::ThirdParty(network), + None => RoomNetwork::Matrix, }) } } diff --git a/crates/ruma-common/src/serde.rs b/crates/ruma-common/src/serde.rs index 665c641f..28e4b81d 100644 --- a/crates/ruma-common/src/serde.rs +++ b/crates/ruma-common/src/serde.rs @@ -65,6 +65,6 @@ where } pub use ruma_macros::{ - AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, Incoming, OrdAsRefStr, - PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde, + AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, PartialEqAsRefStr, + PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde, }; diff --git a/crates/ruma-common/tests/api/mod.rs b/crates/ruma-common/tests/api/mod.rs index a01f92eb..48cedd2d 100644 --- a/crates/ruma-common/tests/api/mod.rs +++ b/crates/ruma-common/tests/api/mod.rs @@ -6,5 +6,4 @@ mod manual_endpoint_impl; mod no_fields; mod optional_headers; mod ruma_api; -mod ruma_api_lifetime; mod ruma_api_macros; diff --git a/crates/ruma-common/tests/api/ruma_api_lifetime.rs b/crates/ruma-common/tests/api/ruma_api_lifetime.rs deleted file mode 100644 index 66c9a8e5..00000000 --- a/crates/ruma-common/tests/api/ruma_api_lifetime.rs +++ /dev/null @@ -1,187 +0,0 @@ -#![allow(clippy::exhaustive_structs)] - -#[derive(Copy, Clone, Debug, ruma_common::serde::Incoming, serde::Serialize)] -pub struct OtherThing<'t> { - pub some: &'t str, - pub t: &'t [u8], -} - -mod empty_response { - use ruma_common::{ - api::{request, response, Metadata}, - metadata, RoomAliasId, RoomId, - }; - - const METADATA: Metadata = metadata! { - method: PUT, - rate_limited: false, - authentication: AccessToken, - history: { - unstable => "/_matrix/client/r0/directory/room/:room_alias", - } - }; - - /// Request type for the `create_alias` endpoint. - #[request] - pub struct Request<'a> { - /// The room alias to set. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, - - /// The room ID to set. - pub room_id: &'a RoomId, - } - - /// Response type for the `create_alias` endpoint. - #[response] - pub struct Response {} -} - -mod nested_types { - use ruma_common::{ - api::{request, response, Metadata}, - metadata, RoomAliasId, - }; - - const METADATA: Metadata = metadata! { - method: PUT, - rate_limited: false, - authentication: AccessToken, - history: { - unstable => "/_matrix/client/r0/directory/room", - } - }; - - /// Request type for the `create_alias` endpoint. - #[request] - pub struct Request<'a> { - /// The room alias to set. - pub room_alias: &'a [Option<&'a RoomAliasId>], - - /// The room ID to set. - pub room_id: &'a [Option>], - } - - /// Response type for the `create_alias` endpoint. - #[response] - pub struct Response {} -} - -mod full_request_response { - use http::header::CONTENT_TYPE; - use ruma_common::{ - api::{request, response, Metadata}, - metadata, - }; - - use super::{IncomingOtherThing, OtherThing}; - - const METADATA: Metadata = metadata! { - method: POST, - rate_limited: false, - authentication: None, - history: { - unstable => "/_matrix/my/endpoint/:thing", - } - }; - - /// Request type for the `no_fields` endpoint. - #[request] - pub struct Request<'a> { - #[ruma_api(query)] - pub abc: &'a str, - #[ruma_api(path)] - pub thing: &'a str, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: &'a str, - pub more: OtherThing<'a>, - } - - /// Response type for the `no_fields` endpoint. - #[response] - pub struct Response { - #[ruma_api(body)] - pub thing: Vec, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } -} - -mod full_request_response_with_query_map { - use http::header::CONTENT_TYPE; - use ruma_common::{ - api::{request, response, Metadata}, - metadata, - }; - - const METADATA: Metadata = metadata! { - method: GET, - rate_limited: false, - authentication: None, - history: { - unstable => "/_matrix/my/endpoint/:thing", - } - }; - - /// Request type for the `no_fields` endpoint. - #[request] - pub struct Request<'a> { - #[ruma_api(query_map)] - // pub abc: &'a [(&'a str, &'a str)], // TODO handle this use case - pub abc: Vec<(String, String)>, - #[ruma_api(path)] - pub thing: &'a str, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: &'a str, - } - - /// Response type for the `no_fields` endpoint. - #[response] - pub struct Response { - #[ruma_api(body)] - pub thing: String, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } -} - -mod query_fields { - use ruma_common::{ - api::{request, response, Metadata}, - metadata, - }; - - const METADATA: Metadata = metadata! { - method: GET, - rate_limited: false, - authentication: None, - history: { - unstable => "/_matrix/client/r0/publicRooms", - } - }; - - /// Request type for the `get_public_rooms` endpoint. - #[request] - pub struct Request<'a> { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, - - /// The server to fetch the public room lists from. - /// - /// `None` means the server this request is sent to. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub server: Option<&'a str>, - } - - /// Response type for the `get_public_rooms` endpoint. - #[response] - pub struct Response {} -} diff --git a/crates/ruma-common/tests/api/ruma_api_macros.rs b/crates/ruma-common/tests/api/ruma_api_macros.rs index 8aa5b08f..09d6d2c9 100644 --- a/crates/ruma-common/tests/api/ruma_api_macros.rs +++ b/crates/ruma-common/tests/api/ruma_api_macros.rs @@ -119,9 +119,9 @@ pub mod raw_body_endpoint { /// Request type for the `newtype_body_endpoint` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { #[ruma_api(raw_body)] - pub file: &'a [u8], + pub file: Vec, } /// Response type for the `newtype_body_endpoint` endpoint. diff --git a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs index 6bec2353..240a3c4f 100644 --- a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs +++ b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -24,14 +24,14 @@ pub mod v1 { /// Request type for the `get_event_authorization` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to get the auth chain for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID to get the auth chain for. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, } /// Response type for the `get_event_authorization` endpoint. @@ -42,9 +42,9 @@ pub mod v1 { pub auth_chain: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and event id. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-federation-api/src/backfill/get_backfill.rs b/crates/ruma-federation-api/src/backfill/get_backfill.rs index 183bbec9..a51ef427 100644 --- a/crates/ruma-federation-api/src/backfill/get_backfill.rs +++ b/crates/ruma-federation-api/src/backfill/get_backfill.rs @@ -10,7 +10,7 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, RoomId, + metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName, }; use serde_json::value::RawValue as RawJsonValue; @@ -25,14 +25,14 @@ pub mod v1 { /// Request type for the `get_backfill` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to backfill. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event IDs to backfill from. #[ruma_api(query)] - pub v: &'a [OwnedEventId], + pub v: Vec, /// The maximum number of PDUs to retrieve, including the given events. #[ruma_api(query)] @@ -53,12 +53,12 @@ pub mod v1 { pub pdus: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with: /// * the given room id. /// * the event IDs to backfill from. /// * the maximum number of PDUs to retrieve, including the given events. - pub fn new(room_id: &'a RoomId, v: &'a [OwnedEventId], limit: UInt) -> Self { + pub fn new(room_id: OwnedRoomId, v: Vec, limit: UInt) -> Self { Self { room_id, v, limit } } } diff --git a/crates/ruma-federation-api/src/device/get_devices.rs b/crates/ruma-federation-api/src/device/get_devices.rs index 80b30d80..08c6a49d 100644 --- a/crates/ruma-federation-api/src/device/get_devices.rs +++ b/crates/ruma-federation-api/src/device/get_devices.rs @@ -13,7 +13,7 @@ pub mod v1 { encryption::{CrossSigningKey, DeviceKeys}, metadata, serde::Raw, - OwnedDeviceId, OwnedUserId, UserId, + OwnedDeviceId, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -28,12 +28,12 @@ pub mod v1 { /// Request type for the `get_devices` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The user ID to retrieve devices for. /// /// Must be a user local to the receiving homeserver. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_devices` endpoint. @@ -61,9 +61,9 @@ pub mod v1 { pub self_signing_key: Option>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id } } } diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms.rs b/crates/ruma-federation-api/src/directory/get_public_rooms.rs index 34ea575f..525a925d 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms.rs @@ -10,7 +10,7 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - directory::{IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, + directory::{PublicRoomsChunk, RoomNetwork}, metadata, }; @@ -26,7 +26,7 @@ pub mod v1 { /// Request type for the `get_public_rooms` endpoint. #[request] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] @@ -35,12 +35,12 @@ pub mod v1 { /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub since: Option<&'a str>, + pub since: Option, /// Network to fetch the public room lists from. #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] #[ruma_api(query)] - pub room_network: RoomNetwork<'a>, + pub room_network: RoomNetwork, } /// Response type for the `get_public_rooms` endpoint. @@ -62,7 +62,7 @@ pub mod v1 { pub total_room_count_estimate: Option, } - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs index 9ceb6c80..84fefb6b 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs @@ -10,7 +10,7 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, + directory::{Filter, PublicRoomsChunk, RoomNetwork}, metadata, }; @@ -26,22 +26,22 @@ pub mod v1 { /// Request type for the `get_public_rooms_filtered` endpoint. #[request] #[derive(Default)] - pub struct Request<'a> { + pub struct Request { /// Limit for the number of results to return. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, /// Pagination token from a previous request. #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option<&'a str>, + pub since: Option, /// Filter to apply to the results. #[serde(default, skip_serializing_if = "Filter::is_empty")] - pub filter: Filter<'a>, + pub filter: Filter, /// Network to fetch the public room lists from. #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] - pub room_network: RoomNetwork<'a>, + pub room_network: RoomNetwork, } /// Response type for the `get_public_rooms_filtered` endpoint. @@ -61,7 +61,7 @@ pub mod v1 { pub total_room_count_estimate: Option, } - impl Request<'_> { + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { Default::default() diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs index 8575e394..27d2275c 100644 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs +++ b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs @@ -12,7 +12,7 @@ pub mod v2 { api::{request, response, Metadata}, metadata, serde::Raw, - MilliSecondsSinceUnixEpoch, ServerName, + MilliSecondsSinceUnixEpoch, OwnedServerName, }; use crate::discovery::ServerSigningKeys; @@ -30,10 +30,10 @@ pub mod v2 { /// Request type for the `get_remote_server_keys` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The server's DNS name to query #[ruma_api(path)] - pub server_name: &'a ServerName, + pub server_name: OwnedServerName, /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates /// will need to be valid until to be useful to the requesting server. @@ -51,10 +51,10 @@ pub mod v2 { pub server_keys: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp. pub fn new( - server_name: &'a ServerName, + server_name: OwnedServerName, minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, ) -> Self { Self { server_name, minimum_valid_until_ts } diff --git a/crates/ruma-federation-api/src/event/get_event.rs b/crates/ruma-federation-api/src/event/get_event.rs index 017380a8..faf3758c 100644 --- a/crates/ruma-federation-api/src/event/get_event.rs +++ b/crates/ruma-federation-api/src/event/get_event.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName, + metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, }; use serde_json::value::RawValue as RawJsonValue; @@ -24,10 +24,10 @@ pub mod v1 { /// Request type for the `get_event` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The event ID to get. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, } /// Response type for the `get_event` endpoint. @@ -44,9 +44,9 @@ pub mod v1 { pub pdu: Box, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given event id. - pub fn new(event_id: &'a EventId) -> Self { + pub fn new(event_id: OwnedEventId) -> Self { Self { event_id } } } diff --git a/crates/ruma-federation-api/src/event/get_missing_events.rs b/crates/ruma-federation-api/src/event/get_missing_events.rs index 5f4f1b21..2ed7ebb4 100644 --- a/crates/ruma-federation-api/src/event/get_missing_events.rs +++ b/crates/ruma-federation-api/src/event/get_missing_events.rs @@ -10,7 +10,7 @@ pub mod v1 { use js_int::{uint, UInt}; use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedEventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -25,10 +25,10 @@ pub mod v1 { /// Request type for the `get_missing_events` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to search in. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The maximum number of events to retrieve. /// @@ -45,10 +45,10 @@ pub mod v1 { /// The latest event IDs that the sender already has. /// /// These are skipped when retrieving the previous events of `latest_events`. - pub earliest_events: &'a [OwnedEventId], + pub earliest_events: Vec, /// The event IDs to retrieve the previous events for. - pub latest_events: &'a [OwnedEventId], + pub latest_events: Vec, } /// Response type for the `get_missing_events` endpoint. @@ -59,12 +59,12 @@ pub mod v1 { pub events: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` for events in the given room with the given constraints. pub fn new( - room_id: &'a RoomId, - earliest_events: &'a [OwnedEventId], - latest_events: &'a [OwnedEventId], + room_id: OwnedRoomId, + earliest_events: Vec, + latest_events: Vec, ) -> Self { Self { room_id, diff --git a/crates/ruma-federation-api/src/event/get_room_state.rs b/crates/ruma-federation-api/src/event/get_room_state.rs index 952134de..29b85bc0 100644 --- a/crates/ruma-federation-api/src/event/get_room_state.rs +++ b/crates/ruma-federation-api/src/event/get_room_state.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -24,14 +24,14 @@ pub mod v1 { /// Request type for the `get_room_state` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to get state for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// An event ID in the room to retrieve the state at. #[ruma_api(query)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, } /// Response type for the `get_room_state` endpoint. @@ -45,9 +45,9 @@ pub mod v1 { pub pdus: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given event ID and room ID. - pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { + pub fn new(event_id: OwnedEventId, room_id: OwnedRoomId) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-federation-api/src/event/get_room_state_ids.rs b/crates/ruma-federation-api/src/event/get_room_state_ids.rs index 0c860192..6b307700 100644 --- a/crates/ruma-federation-api/src/event/get_room_state_ids.rs +++ b/crates/ruma-federation-api/src/event/get_room_state_ids.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, OwnedEventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; const METADATA: Metadata = metadata! { @@ -23,14 +23,14 @@ pub mod v1 { /// Request type for the `get_room_state_ids` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to get state for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// An event ID in the room to retrieve the state at. #[ruma_api(query)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, } /// Response type for the `get_room_state_ids` endpoint. @@ -44,9 +44,9 @@ pub mod v1 { pub pdu_ids: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given event id and room id. - pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { + pub fn new(event_id: OwnedEventId, room_id: OwnedRoomId) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs index e7859760..3e9d5724 100644 --- a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs +++ b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, RoomVersionId, UserId, + metadata, OwnedRoomId, OwnedUserId, RoomVersionId, }; use serde_json::value::RawValue as RawJsonValue; @@ -25,20 +25,20 @@ pub mod v1 { /// Request type for the `create_knock_event_template` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID that should receive the knock. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user ID the knock event will be for. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The room versions the sending has support for. /// - /// Defaults to `&[RoomVersionId::V1]`. + /// Defaults to `vec![RoomVersionId::V1]`. #[ruma_api(query)] - pub ver: &'a [RoomVersionId], + pub ver: Vec, } /// Response type for the `create_knock_event_template` endpoint. @@ -53,10 +53,10 @@ pub mod v1 { pub event: Box, } - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given room ID and user ID. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { - Self { room_id, user_id, ver: &[RoomVersionId::V1] } + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { + Self { room_id, user_id, ver: vec![RoomVersionId::V1] } } } diff --git a/crates/ruma-federation-api/src/knock/send_knock.rs b/crates/ruma-federation-api/src/knock/send_knock.rs index fbdd4b3e..824ca904 100644 --- a/crates/ruma-federation-api/src/knock/send_knock.rs +++ b/crates/ruma-federation-api/src/knock/send_knock.rs @@ -12,7 +12,7 @@ pub mod v1 { events::AnyStrippedStateEvent, metadata, serde::Raw, - EventId, RoomId, + OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -28,18 +28,18 @@ pub mod v1 { /// Request type for the `send_knock` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID that should receive the knock. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the knock event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The PDU. #[ruma_api(body)] - pub pdu: &'a RawJsonValue, + pub pdu: Box, } /// Response type for the `send_knock` endpoint. @@ -49,9 +49,9 @@ pub mod v1 { pub knock_room_state: Vec>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room ID, event ID and knock event. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/create_invite/v1.rs b/crates/ruma-federation-api/src/membership/create_invite/v1.rs index 699834af..5a457ee3 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v1.rs @@ -7,7 +7,7 @@ use ruma_common::{ events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, StateEventType}, metadata, serde::Raw, - EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedUserId, }; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; @@ -23,20 +23,20 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_invite` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that the user is being invited to. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the invite event, generated by the inviting server. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The matrix ID of the user who sent the original `m.room.third_party_invite`. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The name of the inviting homeserver. - pub origin: &'a ServerName, + pub origin: OwnedServerName, /// A timestamp added by the inviting homeserver. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -46,7 +46,7 @@ pub struct Request<'a> { pub kind: StateEventType, /// The user ID of the invited member. - pub state_key: &'a UserId, + pub state_key: OwnedUserId, /// The content of the event. pub content: RoomMemberEventContent, @@ -91,24 +91,24 @@ impl UnsignedEventContent { /// Initial set of fields of `Request`. #[derive(Debug)] #[allow(clippy::exhaustive_structs)] -pub struct RequestInit<'a> { +pub struct RequestInit { /// The room ID that the user is being invited to. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the invite event, generated by the inviting server. - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The matrix ID of the user who sent the original `m.room.third_party_invite`. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The name of the inviting homeserver. - pub origin: &'a ServerName, + pub origin: OwnedServerName, /// A timestamp added by the inviting homeserver. pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The user ID of the invited member. - pub state_key: &'a UserId, + pub state_key: OwnedUserId, /// The content of the event. pub content: RoomMemberEventContent, @@ -117,9 +117,9 @@ pub struct RequestInit<'a> { pub unsigned: UnsignedEventContent, } -impl<'a> From> for Request<'a> { +impl From for Request { /// Creates a new `Request` from `RequestInit`. - fn from(init: RequestInit<'a>) -> Self { + fn from(init: RequestInit) -> Self { Self { room_id: init.room_id, event_id: init.event_id, diff --git a/crates/ruma-federation-api/src/membership/create_invite/v2.rs b/crates/ruma-federation-api/src/membership/create_invite/v2.rs index 602975ea..77b95898 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v2.rs @@ -7,7 +7,7 @@ use ruma_common::{ events::AnyStrippedStateEvent, metadata, serde::Raw, - EventId, RoomId, RoomVersionId, + OwnedEventId, OwnedRoomId, RoomVersionId, }; use serde_json::value::RawValue as RawJsonValue; @@ -22,23 +22,23 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_invite` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that the user is being invited to. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the invite event, generated by the inviting server. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The version of the room where the user is being invited to. - pub room_version: &'a RoomVersionId, + pub room_version: RoomVersionId, /// The invite event which needs to be signed. - pub event: &'a RawJsonValue, + pub event: Box, /// An optional list of simplified events to help the receiver of the invite identify the room. - pub invite_room_state: &'a [Raw], + pub invite_room_state: Vec>, } /// Response type for the `create_invite` endpoint. @@ -48,15 +48,15 @@ pub struct Response { pub event: Box, } -impl<'a> Request<'a> { +impl Request { /// Creates a new `Request` with the given room ID, event ID, room version, event and invite /// room state. pub fn new( - room_id: &'a RoomId, - event_id: &'a EventId, - room_version: &'a RoomVersionId, - event: &'a RawJsonValue, - invite_room_state: &'a [Raw], + room_id: OwnedRoomId, + event_id: OwnedEventId, + room_version: RoomVersionId, + event: Box, + invite_room_state: Vec>, ) -> Self { Self { room_id, event_id, room_version, event, invite_room_state } } diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs index c3948e80..fed8c0b8 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs @@ -4,7 +4,7 @@ use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -21,20 +21,20 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_join_event` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that is about to be joined. /// /// Do not use this. Instead, use the `room_id` field inside the PDU. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the join event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The PDU. #[ruma_api(body)] - pub pdu: &'a RawJsonValue, + pub pdu: Box, } /// Response type for the `create_join_event` endpoint. @@ -46,9 +46,9 @@ pub struct Response { pub room_state: RoomState, } -impl<'a> Request<'a> { +impl Request { /// Creates a new `Request` from the given room ID, event ID and PDU. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs index c8c9d830..546c51b9 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs @@ -4,7 +4,7 @@ use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -21,20 +21,20 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_join_event` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that is about to be joined. /// /// Do not use this. Instead, use the `room_id` field inside the PDU. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the join event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The PDU. #[ruma_api(body)] - pub pdu: &'a RawJsonValue, + pub pdu: Box, } /// Response type for the `create_join_event` endpoint. @@ -45,9 +45,9 @@ pub struct Response { pub room_state: RoomState, } -impl<'a> Request<'a> { +impl Request { /// Creates a new `Request` from the given room ID, event ID and PDU. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs index 16e7373f..2b4c7936 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs @@ -8,7 +8,7 @@ use ruma_common::{ events::{room::member::RoomMemberEventContent, StateEventType}, metadata, serde::Raw, - EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -23,22 +23,22 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_leave_event` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that is about to be left. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the leave event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The user ID of the leaving member. #[ruma_api(query)] - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The name of the leaving homeserver. #[ruma_api(query)] - pub origin: &'a ServerName, + pub origin: OwnedServerName, /// A timestamp added by the leaving homeserver. #[ruma_api(query)] @@ -51,7 +51,7 @@ pub struct Request<'a> { /// The user ID of the leaving member. #[ruma_api(query)] - pub state_key: &'a str, + pub state_key: String, /// The content of the event. #[ruma_api(query)] @@ -80,18 +80,18 @@ pub struct Response { /// new (non-breaking) release of the Matrix specification. #[derive(Debug)] #[allow(clippy::exhaustive_structs)] -pub struct RequestInit<'a> { +pub struct RequestInit { /// The room ID that is about to be left. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the leave event. - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The user ID of the leaving member. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The name of the leaving homeserver. - pub origin: &'a ServerName, + pub origin: OwnedServerName, /// A timestamp added by the leaving homeserver. pub origin_server_ts: MilliSecondsSinceUnixEpoch, @@ -100,7 +100,7 @@ pub struct RequestInit<'a> { pub event_type: StateEventType, /// The user ID of the leaving member. - pub state_key: &'a str, + pub state_key: String, /// The content of the event. pub content: Raw, @@ -109,9 +109,9 @@ pub struct RequestInit<'a> { pub depth: UInt, } -impl<'a> From> for Request<'a> { +impl From for Request { /// Creates a new `Request` from `RequestInit`. - fn from(init: RequestInit<'a>) -> Self { + fn from(init: RequestInit) -> Self { let RequestInit { room_id, event_id, diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs index 7f95c0d9..deeb603e 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs @@ -4,7 +4,7 @@ use ruma_common::{ api::{request, response, Metadata}, - metadata, EventId, RoomId, + metadata, OwnedEventId, OwnedRoomId, }; use serde_json::value::RawValue as RawJsonValue; @@ -19,20 +19,20 @@ const METADATA: Metadata = metadata! { /// Request type for the `create_leave_event` endpoint. #[request] -pub struct Request<'a> { +pub struct Request { /// The room ID that is about to be left. /// /// Do not use this. Instead, use the `room_id` field inside the PDU. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event ID for the leave event. #[ruma_api(path)] - pub event_id: &'a EventId, + pub event_id: OwnedEventId, /// The PDU. #[ruma_api(body)] - pub pdu: &'a RawJsonValue, + pub pdu: Box, } /// Response type for the `create_leave_event` endpoint. @@ -40,9 +40,9 @@ pub struct Request<'a> { #[derive(Default)] pub struct Response {} -impl<'a> Request<'a> { +impl Request { /// Creates a new `Request` from the given room ID, event ID and PDU. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { + pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box) -> Self { Self { room_id, event_id, pdu } } } diff --git a/crates/ruma-federation-api/src/membership/prepare_join_event.rs b/crates/ruma-federation-api/src/membership/prepare_join_event.rs index 2638e1cc..64055d35 100644 --- a/crates/ruma-federation-api/src/membership/prepare_join_event.rs +++ b/crates/ruma-federation-api/src/membership/prepare_join_event.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, RoomVersionId, UserId, + metadata, OwnedRoomId, OwnedUserId, RoomVersionId, }; use serde_json::value::RawValue as RawJsonValue; @@ -24,21 +24,21 @@ pub mod v1 { /// Request type for the `create_join_event_template` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID that is about to be joined. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user ID the join event will be for. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// The room versions the sending server has support for. /// /// Defaults to `&[RoomVersionId::V1]`. #[ruma_api(query)] #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")] - pub ver: &'a [RoomVersionId], + pub ver: Vec, } /// Response type for the `create_join_event_template` endpoint. @@ -56,14 +56,14 @@ pub mod v1 { vec![RoomVersionId::V1] } - fn is_default_ver(ver: &&[RoomVersionId]) -> bool { - **ver == [RoomVersionId::V1] + fn is_default_ver(ver: &[RoomVersionId]) -> bool { + *ver == [RoomVersionId::V1] } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room id and user id. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { - Self { room_id, user_id, ver: &[RoomVersionId::V1] } + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { + Self { room_id, user_id, ver: vec![RoomVersionId::V1] } } } diff --git a/crates/ruma-federation-api/src/membership/prepare_leave_event.rs b/crates/ruma-federation-api/src/membership/prepare_leave_event.rs index 7fc445cd..144a7300 100644 --- a/crates/ruma-federation-api/src/membership/prepare_leave_event.rs +++ b/crates/ruma-federation-api/src/membership/prepare_leave_event.rs @@ -10,7 +10,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, RoomId, RoomVersionId, UserId, + metadata, OwnedRoomId, OwnedUserId, RoomVersionId, }; use serde_json::value::RawValue as RawJsonValue; @@ -25,14 +25,14 @@ pub mod v1 { /// Request type for the `get_leave_event` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID that is about to be left. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The user ID the leave event will be for. #[ruma_api(path)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, } /// Response type for the `get_leave_event` endpoint. @@ -50,11 +50,11 @@ pub mod v1 { pub event: Box, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with: /// * the room ID that is about to be left. /// * the user ID the leave event will be for. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + pub fn new(room_id: OwnedRoomId, user_id: OwnedUserId) -> Self { Self { room_id, user_id } } } diff --git a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs index f9f436fd..84f6b63c 100644 --- a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs +++ b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs @@ -23,10 +23,10 @@ pub mod v1 { /// Request type for the `get_openid_userinfo` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The OpenID access token to get information about the owner for. #[ruma_api(query)] - pub access_token: &'a str, + pub access_token: String, } /// Response type for the `get_openid_userinfo` endpoint. @@ -36,9 +36,9 @@ pub mod v1 { pub sub: OwnedUserId, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given access token. - pub fn new(access_token: &'a str) -> Self { + pub fn new(access_token: String) -> Self { Self { access_token } } } diff --git a/crates/ruma-federation-api/src/query/get_custom_information.rs b/crates/ruma-federation-api/src/query/get_custom_information.rs index fe8f1969..0bfb7ff6 100644 --- a/crates/ruma-federation-api/src/query/get_custom_information.rs +++ b/crates/ruma-federation-api/src/query/get_custom_information.rs @@ -27,10 +27,10 @@ pub mod v1 { /// Request type for the `get_custom_information` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The type of query to make. #[ruma_api(path)] - pub query_type: &'a str, + pub query_type: String, /// The query parameters. #[ruma_api(query_map)] @@ -45,9 +45,9 @@ pub mod v1 { pub body: JsonValue, } - impl<'a> Request<'a> { + impl Request { /// Creates a new request with the given type and query parameters. - pub fn new(query_type: &'a str, params: BTreeMap) -> Self { + pub fn new(query_type: String, params: BTreeMap) -> Self { Self { query_type, params } } } diff --git a/crates/ruma-federation-api/src/query/get_profile_information.rs b/crates/ruma-federation-api/src/query/get_profile_information.rs index 22e24d52..8f89f1bb 100644 --- a/crates/ruma-federation-api/src/query/get_profile_information.rs +++ b/crates/ruma-federation-api/src/query/get_profile_information.rs @@ -11,7 +11,7 @@ pub mod v1 { api::{request, response, Metadata}, metadata, serde::StringEnum, - OwnedMxcUri, UserId, + OwnedMxcUri, OwnedUserId, }; use crate::PrivOwnedStr; @@ -27,15 +27,15 @@ pub mod v1 { /// Request type for the `get_profile_information` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// User ID to query. #[ruma_api(query)] - pub user_id: &'a UserId, + pub user_id: OwnedUserId, /// Profile field to query. #[serde(skip_serializing_if = "Option::is_none")] #[ruma_api(query)] - pub field: Option<&'a ProfileField>, + pub field: Option, } /// Response type for the `get_profile_information` endpoint. @@ -66,9 +66,9 @@ pub mod v1 { pub blurhash: Option, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { + pub fn new(user_id: OwnedUserId) -> Self { Self { user_id, field: None } } } diff --git a/crates/ruma-federation-api/src/query/get_room_information.rs b/crates/ruma-federation-api/src/query/get_room_information.rs index 4c0f0f8a..6d694caf 100644 --- a/crates/ruma-federation-api/src/query/get_room_information.rs +++ b/crates/ruma-federation-api/src/query/get_room_information.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, OwnedServerName, RoomAliasId, + metadata, OwnedRoomAliasId, OwnedRoomId, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -23,10 +23,10 @@ pub mod v1 { /// Request type for the `get_room_information` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// Room alias to query. #[ruma_api(query)] - pub room_alias: &'a RoomAliasId, + pub room_alias: OwnedRoomAliasId, } /// Response type for the `get_room_information` endpoint. @@ -39,9 +39,9 @@ pub mod v1 { pub servers: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given room alias ID. - pub fn new(room_alias: &'a RoomAliasId) -> Self { + pub fn new(room_alias: OwnedRoomAliasId) -> Self { Self { room_alias } } } diff --git a/crates/ruma-federation-api/src/space/get_hierarchy.rs b/crates/ruma-federation-api/src/space/get_hierarchy.rs index ec9ba151..d8b2a92f 100644 --- a/crates/ruma-federation-api/src/space/get_hierarchy.rs +++ b/crates/ruma-federation-api/src/space/get_hierarchy.rs @@ -9,7 +9,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, - metadata, OwnedRoomId, RoomId, + metadata, OwnedRoomId, }; use crate::space::{SpaceHierarchyChildSummary, SpaceHierarchyParentSummary}; @@ -26,10 +26,10 @@ pub mod v1 { /// Request type for the `hierarchy` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID of the space to get a hierarchy for. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// Whether or not the server should only consider suggested rooms. /// @@ -57,9 +57,9 @@ pub mod v1 { pub room: SpaceHierarchyParentSummary, } - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given room ID. - pub fn new(room_id: &'a RoomId) -> Self { + pub fn new(room_id: OwnedRoomId) -> Self { Self { room_id, suggested_only: false } } } diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs index 85cc3add..b0c8871d 100644 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs +++ b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs @@ -15,7 +15,7 @@ pub mod v1 { api::{request, response, Metadata}, metadata, thirdparty::Medium, - OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, UserId, + OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -30,42 +30,42 @@ pub mod v1 { /// Request type for the `bind_callback` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The type of third party identifier. /// /// Currently only `Medium::Email` is supported. - pub medium: &'a Medium, + pub medium: Medium, /// The third party identifier itself. /// /// For example: an email address. - pub address: &'a str, + pub address: String, /// The user that is now bound to the third party identifier. - pub mxid: &'a UserId, + pub mxid: OwnedUserId, /// A list of pending invites that the third party identifier has received. - pub invites: &'a [ThirdPartyInvite], + pub invites: Vec, } /// Response type for the `bind_callback` endpoint. #[response] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given medium, address, user ID and third party invites. pub fn new( - medium: &'a Medium, - address: &'a str, - mxid: &'a UserId, - invites: &'a [ThirdPartyInvite], + medium: Medium, + address: String, + mxid: OwnedUserId, + invites: Vec, ) -> Self { Self { medium, address, mxid, invites } } /// Creates a new `Request` with the given email address, user ID and third party invites. - pub fn email(address: &'a str, mxid: &'a UserId, invites: &'a [ThirdPartyInvite]) -> Self { - Self::new(&Medium::Email, address, mxid, invites) + pub fn email(address: String, mxid: OwnedUserId, invites: Vec) -> Self { + Self::new(Medium::Email, address, mxid, invites) } } diff --git a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs index 9961697a..5752568b 100644 --- a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs +++ b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs @@ -14,7 +14,7 @@ pub mod v1 { use ruma_common::{ api::{request, response, Metadata}, events::{room::member::ThirdPartyInvite, StateEventType}, - metadata, RoomId, UserId, + metadata, OwnedRoomId, OwnedUserId, }; const METADATA: Metadata = metadata! { @@ -28,10 +28,10 @@ pub mod v1 { /// Request type for the `exchange_invite` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The room ID to exchange a third party invite in. #[ruma_api(path)] - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The event type. /// @@ -40,13 +40,13 @@ pub mod v1 { pub kind: StateEventType, /// The user ID of the user who sent the original invite event. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The user ID of the invited user. - pub state_key: &'a UserId, + pub state_key: OwnedUserId, /// The content of the invite event. - pub content: &'a ThirdPartyInvite, + pub content: ThirdPartyInvite, } /// Response type for the `exchange_invite` endpoint. @@ -54,13 +54,13 @@ pub mod v1 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` for a third party invite exchange pub fn new( - room_id: &'a RoomId, - sender: &'a UserId, - state_key: &'a UserId, - content: &'a ThirdPartyInvite, + room_id: OwnedRoomId, + sender: OwnedUserId, + state_key: OwnedUserId, + content: ThirdPartyInvite, ) -> Self { Self { room_id, kind: StateEventType::RoomMember, sender, state_key, content } } diff --git a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs index 003fef0c..a5036870 100644 --- a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs +++ b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs @@ -13,7 +13,7 @@ pub mod v1 { api::{request, response, Metadata}, metadata, serde::Raw, - MilliSecondsSinceUnixEpoch, OwnedEventId, ServerName, TransactionId, + MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, OwnedTransactionId, }; use serde_json::value::RawValue as RawJsonValue; @@ -30,13 +30,13 @@ pub mod v1 { /// Request type for the `send_transaction_message` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// A transaction ID unique between sending and receiving homeservers. #[ruma_api(path)] - pub transaction_id: &'a TransactionId, + pub transaction_id: OwnedTransactionId, /// The server_name of the homeserver sending this transaction. - pub origin: &'a ServerName, + pub origin: OwnedServerName, /// POSIX timestamp in milliseconds on the originating homeserver when this transaction /// started. @@ -52,13 +52,13 @@ pub mod v1 { feature = "unstable-unspecified", serde(default, skip_serializing_if = "<[_]>::is_empty") )] - pub pdus: &'a [Box], + pub pdus: Vec>, /// List of ephemeral messages. /// /// Must not be more than 100 items. #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub edus: &'a [Raw], + pub edus: Vec>, } /// Response type for the `send_transaction_message` endpoint. @@ -74,16 +74,16 @@ pub mod v1 { pub pdus: BTreeMap>, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given transaction ID, origin, timestamp. /// /// The PDU and EDU lists will start off empty. pub fn new( - transaction_id: &'a TransactionId, - origin: &'a ServerName, + transaction_id: OwnedTransactionId, + origin: OwnedServerName, origin_server_ts: MilliSecondsSinceUnixEpoch, ) -> Self { - Self { transaction_id, origin, origin_server_ts, pdus: &[], edus: &[] } + Self { transaction_id, origin, origin_server_ts, pdus: vec![], edus: vec![] } } } diff --git a/crates/ruma-identity-service-api/src/association/bind_3pid.rs b/crates/ruma-identity-service-api/src/association/bind_3pid.rs index 26faa7d7..7efb0a76 100644 --- a/crates/ruma-identity-service-api/src/association/bind_3pid.rs +++ b/crates/ruma-identity-service-api/src/association/bind_3pid.rs @@ -11,7 +11,8 @@ pub mod v2 { api::{request, response, Metadata}, metadata, thirdparty::Medium, - ClientSecret, MilliSecondsSinceUnixEpoch, OwnedUserId, ServerSignatures, SessionId, UserId, + MilliSecondsSinceUnixEpoch, OwnedClientSecret, OwnedSessionId, OwnedUserId, + ServerSignatures, }; const METADATA: Metadata = metadata! { @@ -25,15 +26,15 @@ pub mod v2 { /// Request type for the `bind_3pid` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The session ID generated by the `requestToken` call. - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret passed to the `requestToken` call. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The Matrix user ID to associate with the 3PIDs. - pub mxid: &'a UserId, + pub mxid: OwnedUserId, } /// Response type for the `bind_3pid` endpoint. @@ -62,9 +63,13 @@ pub mod v2 { pub signatures: ServerSignatures, } - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given session ID, client secret and Matrix user ID. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, mxid: &'a UserId) -> Self { + pub fn new( + sid: OwnedSessionId, + client_secret: OwnedClientSecret, + mxid: OwnedUserId, + ) -> Self { Self { sid, client_secret, mxid } } } diff --git a/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs b/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs index 77974c61..15e04986 100644 --- a/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs +++ b/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs @@ -12,7 +12,7 @@ pub mod v2 { api::{request, response, Metadata}, metadata, thirdparty::Medium, - ClientSecret, SessionId, + OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -26,14 +26,14 @@ pub mod v2 { /// Request type for the `check_3pid_validity` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The Session ID generated by the `requestToken` call. #[ruma_api(query)] - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret passed to the `requestToken` call. #[ruma_api(query)] - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, } /// Response type for the `check_3pid_validity` endpoint. @@ -49,9 +49,9 @@ pub mod v2 { pub validated_at: UInt, } - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given Session ID and client secret. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret) -> Self { + pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret) -> Self { Self { sid, client_secret } } } diff --git a/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs b/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs index 5c72c493..9974d233 100644 --- a/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs +++ b/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs @@ -10,7 +10,7 @@ pub mod v2 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -24,12 +24,12 @@ pub mod v2 { /// Request type for the `create_email_validation_session` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// A unique string generated by the client, and used to identify the validation attempt. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The email address to validate. - pub email: &'a str, + pub email: String, /// The server will only send an email if the send_attempt is a number greater than the /// most recent one which it has seen, scoped to that email + client_secret pair. @@ -38,7 +38,7 @@ pub mod v2 { /// When the validation is completed, the identity server will redirect the user to this /// URL. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, } /// Response type for the `create_email_validation_session` endpoint. @@ -50,14 +50,14 @@ pub mod v2 { pub sid: OwnedSessionId, } - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given client secret, email ID, `send_attempt` number, /// and the link to redirect to after validation. pub fn new( - client_secret: &'a ClientSecret, - email: &'a str, + client_secret: OwnedClientSecret, + email: String, send_attempt: UInt, - next_link: Option<&'a str>, + next_link: Option, ) -> Self { Self { client_secret, email, send_attempt, next_link } } diff --git a/crates/ruma-identity-service-api/src/association/email/validate_email.rs b/crates/ruma-identity-service-api/src/association/email/validate_email.rs index 07d3fa9e..167ecea0 100644 --- a/crates/ruma-identity-service-api/src/association/email/validate_email.rs +++ b/crates/ruma-identity-service-api/src/association/email/validate_email.rs @@ -9,7 +9,7 @@ pub mod v2 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -23,15 +23,15 @@ pub mod v2 { /// Request type for the `validate_email` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The session ID, generated by the `requestToken` call. - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret that was supplied to the `requestToken` call. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The token generated by the `requestToken` call and emailed to the user. - pub token: &'a str, + pub token: String, } /// Response type for the `validate_email` endpoint. @@ -41,9 +41,9 @@ pub mod v2 { pub success: bool, } - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given session ID, client secret and token. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { + pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret, token: String) -> Self { Self { sid, client_secret, token } } } diff --git a/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs b/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs index 33a9a4a8..4a545407 100644 --- a/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs +++ b/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs @@ -9,7 +9,7 @@ pub mod v2 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -23,18 +23,18 @@ pub mod v2 { /// Request type for the `validate_email_by_end_user` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The session ID, generated by the `requestToken` call. #[ruma_api(query)] - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret that was supplied to the `requestToken` call. #[ruma_api(query)] - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The token generated by the `requestToken` call and emailed to the user. #[ruma_api(query)] - pub token: &'a str, + pub token: String, } /// Response type for the `validate_email_by_end_user` endpoint. @@ -42,9 +42,9 @@ pub mod v2 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given session ID, client secret and token. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { + pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret, token: String) -> Self { Self { sid, client_secret, token } } } diff --git a/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs b/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs index 2e79548b..ce45eee0 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs @@ -10,7 +10,7 @@ pub mod v2 { use js_int::UInt; use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, OwnedSessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -24,16 +24,16 @@ pub mod v2 { /// Request type for the `create_msisdn_validation_session` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// A unique string generated by the client, and used to identify the validation attempt. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in /// `phone_number` should be parsed as if it were dialled from. - pub country: &'a str, + pub country: String, /// The phone number to validate. - pub phone_number: &'a str, + pub phone_number: String, /// The server will only send an SMS if the send_attempt is a number greater than the most /// recent one which it has seen, scoped to that `country` + `phone_number` + @@ -43,7 +43,7 @@ pub mod v2 { /// When the validation is completed, the identity server will redirect the user to this /// URL. #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + pub next_link: Option, } /// Response type for the `create_msisdn_validation_session` endpoint. @@ -55,15 +55,15 @@ pub mod v2 { pub sid: OwnedSessionId, } - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given client secret, country code, phone number, the /// `send_attempt` number and the next link to go to after validation. pub fn new( - client_secret: &'a ClientSecret, - country: &'a str, - phone_number: &'a str, + client_secret: OwnedClientSecret, + country: String, + phone_number: String, send_attempt: UInt, - next_link: Option<&'a str>, + next_link: Option, ) -> Self { Self { client_secret, country, phone_number, send_attempt, next_link } } diff --git a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs index 9b2179d0..f425bbbb 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs @@ -9,7 +9,7 @@ pub mod v2 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -23,15 +23,15 @@ pub mod v2 { /// Request type for the `validate_msisdn` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The session ID, generated by the `requestToken` call. - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret that was supplied to the `requestToken` call. - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The token generated by the `requestToken` call and sent to the user. - pub token: &'a str, + pub token: String, } /// Response type for the `validate_msisdn` endpoint. @@ -41,9 +41,9 @@ pub mod v2 { pub success: bool, } - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given session ID, client secret and token. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { + pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret, token: String) -> Self { Self { sid, client_secret, token } } } diff --git a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs index fc5404d9..f90934db 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs @@ -9,7 +9,7 @@ pub mod v2 { use ruma_common::{ api::{request, response, Metadata}, - metadata, ClientSecret, SessionId, + metadata, OwnedClientSecret, OwnedSessionId, }; const METADATA: Metadata = metadata! { @@ -23,18 +23,18 @@ pub mod v2 { /// Request type for the `validate_email_by_end_user` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The session ID, generated by the `requestToken` call. #[ruma_api(query)] - pub sid: &'a SessionId, + pub sid: OwnedSessionId, /// The client secret that was supplied to the `requestToken` call. #[ruma_api(query)] - pub client_secret: &'a ClientSecret, + pub client_secret: OwnedClientSecret, /// The token generated by the `requestToken` call and sent to the user. #[ruma_api(query)] - pub token: &'a str, + pub token: String, } /// Response type for the `validate_email_by_end_user` endpoint. @@ -42,9 +42,9 @@ pub mod v2 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Create a new `Request` with the given session ID, client secret and token. - pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { + pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret, token: String) -> Self { Self { sid, client_secret, token } } } diff --git a/crates/ruma-identity-service-api/src/association/unbind_3pid.rs b/crates/ruma-identity-service-api/src/association/unbind_3pid.rs index ab09f855..0a12425c 100644 --- a/crates/ruma-identity-service-api/src/association/unbind_3pid.rs +++ b/crates/ruma-identity-service-api/src/association/unbind_3pid.rs @@ -11,8 +11,7 @@ pub mod v2 { api::{request, response, Metadata}, metadata, thirdparty::Medium, - user_id::UserId, - ClientSecret, OwnedSessionId, + ClientSecret, OwnedSessionId, OwnedUserId, }; use serde::{Deserialize, Serialize}; @@ -27,22 +26,22 @@ pub mod v2 { /// Request type for the `unbind_3pid` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The proof that the client owns the 3PID. /// /// If this is not provided, the request must be signed by the homeserver which controls /// the `mxid`. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub threepid_ownership_proof: Option<&'a ThreePidOwnershipProof>, + pub threepid_ownership_proof: Option, /// The Matrix user ID to remove from the 3PIDs. - pub mxid: &'a UserId, + pub mxid: OwnedUserId, /// The 3PID to remove. /// /// Must match the 3PID used to generate the session if using `sid` and `client_secret` to /// authenticate this request. - pub threepid: &'a ThirdPartyId, + pub threepid: ThirdPartyId, } /// Response type for the `unbind_3pid` endpoint. @@ -50,12 +49,12 @@ pub mod v2 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given Session ID, client secret, Matrix user ID and 3PID. pub fn new( - threepid_ownership_proof: Option<&'a ThreePidOwnershipProof>, - mxid: &'a UserId, - threepid: &'a ThirdPartyId, + threepid_ownership_proof: Option, + mxid: OwnedUserId, + threepid: ThirdPartyId, ) -> Self { Self { threepid_ownership_proof, mxid, threepid } } diff --git a/crates/ruma-identity-service-api/src/authentication/register.rs b/crates/ruma-identity-service-api/src/authentication/register.rs index 4d6397e2..d6021a95 100644 --- a/crates/ruma-identity-service-api/src/authentication/register.rs +++ b/crates/ruma-identity-service-api/src/authentication/register.rs @@ -12,7 +12,7 @@ pub mod v2 { use ruma_common::{ api::{request, response, Metadata}, authentication::TokenType, - metadata, ServerName, + metadata, OwnedServerName, }; const METADATA: Metadata = metadata! { @@ -26,20 +26,20 @@ pub mod v2 { /// Request type for the `register_account` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// An access token the consumer may use to verify the identity of the person who generated /// the token. /// /// This is given to the federation API `GET /openid/userinfo` to verify the user's /// identity. - pub access_token: &'a str, + pub access_token: String, /// The string `Bearer`. pub token_type: TokenType, /// The homeserver domain the consumer should use when attempting to verify the user's /// identity. - pub matrix_server_name: &'a ServerName, + pub matrix_server_name: OwnedServerName, /// The number of seconds before this token expires and a new one must be generated. #[serde(with = "ruma_common::serde::duration::secs")] @@ -54,12 +54,12 @@ pub mod v2 { pub token: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given parameters. pub fn new( - access_token: &'a str, + access_token: String, token_type: TokenType, - matrix_server_name: &'a ServerName, + matrix_server_name: OwnedServerName, expires_in: Duration, ) -> Self { Self { access_token, token_type, matrix_server_name, expires_in } diff --git a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs index 6888b5f9..9911a5af 100644 --- a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs +++ b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs @@ -11,7 +11,7 @@ pub mod v2 { api::{request, response, Metadata}, metadata, serde::Base64, - OwnedUserId, ServerSignatures, UserId, + OwnedUserId, ServerSignatures, }; const METADATA: Metadata = metadata! { @@ -25,15 +25,15 @@ pub mod v2 { /// Request type for the `sign_invitation_ed25519` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The Matrix user ID of the user accepting the invitation. - pub mxid: &'a UserId, + pub mxid: OwnedUserId, /// The token from the call to store-invite. - pub token: &'a str, + pub token: String, /// The private key, encoded as unpadded base64. - pub private_key: &'a Base64, + pub private_key: Base64, } /// Response type for the `sign_invitation_ed25519` endpoint. @@ -52,9 +52,9 @@ pub mod v2 { pub token: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a `Request` with the given Matrix user ID, token and private_key. - pub fn new(mxid: &'a UserId, token: &'a str, private_key: &'a Base64) -> Self { + pub fn new(mxid: OwnedUserId, token: String, private_key: Base64) -> Self { Self { mxid, token, private_key } } } diff --git a/crates/ruma-identity-service-api/src/invitation/store_invitation.rs b/crates/ruma-identity-service-api/src/invitation/store_invitation.rs index c9121559..a05b054e 100644 --- a/crates/ruma-identity-service-api/src/invitation/store_invitation.rs +++ b/crates/ruma-identity-service-api/src/invitation/store_invitation.rs @@ -12,7 +12,7 @@ pub mod v2 { metadata, room::RoomType, thirdparty::Medium, - MxcUri, RoomAliasId, RoomId, UserId, + OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, }; use serde::{ser::SerializeSeq, Deserialize, Serialize}; @@ -27,58 +27,58 @@ pub mod v2 { /// Request type for the `store_invitation` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The type of the third party identifier for the invited user. /// /// Currently, only `Medium::Email` is supported. - pub medium: &'a Medium, + pub medium: Medium, /// The email address of the invited user. - pub address: &'a str, + pub address: String, /// The Matrix room ID to which the user is invited. - pub room_id: &'a RoomId, + pub room_id: OwnedRoomId, /// The Matrix user ID of the inviting user. - pub sender: &'a UserId, + pub sender: OwnedUserId, /// The Matrix room alias for the room to which the user is invited. /// /// This should be retrieved from the `m.room.canonical` state event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias: Option<&'a RoomAliasId>, + pub room_alias: Option, /// The Content URI for the room to which the user is invited. /// /// This should be retrieved from the `m.room.avatar` state event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_avatar_url: Option<&'a MxcUri>, + pub room_avatar_url: Option, /// The `join_rule` for the room to which the user is invited. /// /// This should be retrieved from the `m.room.join_rules` state event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_join_rules: Option<&'a str>, + pub room_join_rules: Option, /// The name of the room to which the user is invited. /// /// This should be retrieved from the `m.room.name` state event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_name: Option<&'a str>, + pub room_name: Option, /// The type of the room to which the user is invited. /// /// This should be retrieved from the `m.room.create` state event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_type: Option<&'a RoomType>, + pub room_type: Option, /// The display name of the user ID initiating the invite. #[serde(skip_serializing_if = "Option::is_none")] - pub sender_display_name: Option<&'a str>, + pub sender_display_name: Option, /// The Content URI for the avater of the user ID initiating the invite. #[serde(skip_serializing_if = "Option::is_none")] - pub sender_avatar_url: Option<&'a MxcUri>, + pub sender_avatar_url: Option, } /// Response type for the `store_invitation` endpoint. @@ -99,13 +99,13 @@ pub mod v2 { pub display_name: String, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request with the given medium, email address, room ID and sender. pub fn new( - medium: &'a Medium, - address: &'a str, - room_id: &'a RoomId, - sender: &'a UserId, + medium: Medium, + address: String, + room_id: OwnedRoomId, + sender: OwnedUserId, ) -> Self { Self { medium, @@ -123,8 +123,8 @@ pub mod v2 { } /// Creates a new `Request` with the given email address, room ID and sender. - pub fn email(address: &'a str, room_id: &'a RoomId, sender: &'a UserId) -> Self { - Self::new(&Medium::Email, address, room_id, sender) + pub fn email(address: String, room_id: OwnedRoomId, sender: OwnedUserId) -> Self { + Self::new(Medium::Email, address, room_id, sender) } } diff --git a/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs b/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs index 4d322e86..0cb5d863 100644 --- a/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs +++ b/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs @@ -25,10 +25,10 @@ pub mod v2 { /// Request type for the `check_public_key_validity` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// Base64-encoded (no padding) public key to check for validity. #[ruma_api(query)] - pub public_key: &'a Base64, + pub public_key: Base64, } /// Response type for the `check_public_key_validity` endpoint. @@ -38,9 +38,9 @@ pub mod v2 { pub valid: bool, } - impl<'a> Request<'a> { + impl Request { /// Create a `Request` with the given base64-encoded (unpadded) public key. - pub fn new(public_key: &'a Base64) -> Self { + pub fn new(public_key: Base64) -> Self { Self { public_key } } } diff --git a/crates/ruma-identity-service-api/src/keys/get_public_key.rs b/crates/ruma-identity-service-api/src/keys/get_public_key.rs index 0ba203d8..14d906bb 100644 --- a/crates/ruma-identity-service-api/src/keys/get_public_key.rs +++ b/crates/ruma-identity-service-api/src/keys/get_public_key.rs @@ -11,7 +11,7 @@ pub mod v2 { api::{request, response, Metadata}, metadata, serde::Base64, - ServerSigningKeyId, + OwnedServerSigningKeyId, }; const METADATA: Metadata = metadata! { @@ -25,10 +25,10 @@ pub mod v2 { /// Request type for the `get_public_key` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The ID of the key. #[ruma_api(path)] - pub key_id: &'a ServerSigningKeyId, + pub key_id: OwnedServerSigningKeyId, } /// Response type for the `get_public_key` endpoint. @@ -38,9 +38,9 @@ pub mod v2 { pub public_key: Base64, } - impl<'a> Request<'a> { + impl Request { /// Create a `Request` with the given key_id. - pub fn new(key_id: &'a ServerSigningKeyId) -> Self { + pub fn new(key_id: OwnedServerSigningKeyId) -> Self { Self { key_id } } } diff --git a/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs b/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs index 563fc09b..ddc5ce11 100644 --- a/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs +++ b/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs @@ -24,10 +24,10 @@ pub mod v2 { /// Request type for the `validate_ephemeral_key` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The unpadded base64-encoded short-term public key to check. #[ruma_api(query)] - pub public_key: &'a Base64, + pub public_key: Base64, } /// Response type for the `validate_ephemeral_key` endpoint. @@ -37,9 +37,9 @@ pub mod v2 { pub valid: bool, } - impl<'a> Request<'a> { + impl Request { /// Create a `Request` with the given base64-encoded (unpadded) short-term public key. - pub fn new(public_key: &'a Base64) -> Self { + pub fn new(public_key: Base64) -> Self { Self { public_key } } } diff --git a/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs b/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs index 74f760e2..2545d87e 100644 --- a/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs +++ b/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs @@ -27,20 +27,20 @@ pub mod v2 { /// Request type for the `lookup_3pid` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The algorithm the client is using to encode the `addresses`. This should be one of the /// available options from `/hash_details`. - pub algorithm: &'a IdentifierHashingAlgorithm, + pub algorithm: IdentifierHashingAlgorithm, /// The pepper from `/hash_details`. This is required even when the `algorithm` does not /// make use of it. - pub pepper: &'a str, + pub pepper: String, /// The addresses to look up. /// /// The format of the entries here depend on the `algorithm` used. Note that queries which /// have been incorrectly hashed or formatted will lead to no matches. - pub addresses: &'a [String], + pub addresses: Vec, } /// Response type for the `lookup_3pid` endpoint. @@ -53,12 +53,12 @@ pub mod v2 { pub mappings: BTreeMap, } - impl<'a> Request<'a> { + impl Request { /// Create a `Request` with algorithm, pepper and addresses to loop up. pub fn new( - algorithm: &'a IdentifierHashingAlgorithm, - pepper: &'a str, - addresses: &'a [String], + algorithm: IdentifierHashingAlgorithm, + pepper: String, + addresses: Vec, ) -> Self { Self { algorithm, pepper, addresses } } diff --git a/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs b/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs index ec9362e8..8ea07a55 100644 --- a/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs +++ b/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs @@ -23,11 +23,11 @@ pub mod v2 { /// Request type for the `accept_terms_of_service` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// The URLs the user is accepting in this request. /// /// An example is `https://example.org/somewhere/terms-2.0-en.html`. - pub user_accepts: &'a [String], + pub user_accepts: Vec, } /// Response type for the `accept_terms_of_service` endpoint. @@ -35,9 +35,9 @@ pub mod v2 { #[derive(Default)] pub struct Response {} - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given URLs which the user accepts. - pub fn new(user_accepts: &'a [String]) -> Self { + pub fn new(user_accepts: Vec) -> Self { Self { user_accepts } } } diff --git a/crates/ruma-macros/src/api/request.rs b/crates/ruma-macros/src/api/request.rs index f4d08f35..c81253f3 100644 --- a/crates/ruma-macros/src/api/request.rs +++ b/crates/ruma-macros/src/api/request.rs @@ -1,17 +1,14 @@ -use std::collections::BTreeSet; - use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, - DeriveInput, Field, Generics, Ident, ItemStruct, Lifetime, Token, Type, + DeriveInput, Field, Generics, Ident, ItemStruct, Token, Type, }; use super::{ attribute::{DeriveRequestMeta, RequestMeta}, ensure_feature_presence, - util::collect_lifetime_idents, }; use crate::util::import_ruma_common; @@ -32,15 +29,8 @@ pub fn expand_request(attr: RequestAttr, item: ItemStruct) -> TokenStream { quote! { #maybe_feature_error - #[derive( - Clone, - Debug, - #ruma_macros::Request, - #ruma_common::serde::Incoming, - #ruma_common::serde::_FakeDeriveSerde, - )] + #[derive(Clone, Debug, #ruma_macros::Request, #ruma_common::serde::_FakeDeriveSerde)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize, #ruma_macros::_FakeDeriveRumaApi)] #[ruma_api(error = #error_ty)] #item } @@ -60,26 +50,7 @@ pub fn expand_derive_request(input: DeriveInput) -> syn::Result { _ => panic!("This derive macro only works on structs"), }; - let mut lifetimes = RequestLifetimes::default(); - let fields = fields - .into_iter() - .map(|f| { - let f = RequestField::try_from(f)?; - let ty = &f.inner.ty; - - match &f.kind { - RequestFieldKind::Header(_) => collect_lifetime_idents(&mut lifetimes.header, ty), - RequestFieldKind::Body => collect_lifetime_idents(&mut lifetimes.body, ty), - RequestFieldKind::NewtypeBody => collect_lifetime_idents(&mut lifetimes.body, ty), - RequestFieldKind::RawBody => collect_lifetime_idents(&mut lifetimes.body, ty), - RequestFieldKind::Path => collect_lifetime_idents(&mut lifetimes.path, ty), - RequestFieldKind::Query => collect_lifetime_idents(&mut lifetimes.query, ty), - RequestFieldKind::QueryMap => collect_lifetime_idents(&mut lifetimes.query, ty), - } - - Ok(f) - }) - .collect::>()?; + let fields = fields.into_iter().map(RequestField::try_from).collect::>()?; let mut error_ty = None; @@ -101,7 +72,6 @@ pub fn expand_derive_request(input: DeriveInput) -> syn::Result { ident: input.ident, generics: input.generics, fields, - lifetimes, error_ty: error_ty.expect("missing error_ty attribute"), }; @@ -115,18 +85,9 @@ pub fn expand_derive_request(input: DeriveInput) -> syn::Result { }) } -#[derive(Default)] -struct RequestLifetimes { - pub body: BTreeSet, - pub path: BTreeSet, - pub query: BTreeSet, - pub header: BTreeSet, -} - struct Request { ident: Ident, generics: Generics, - lifetimes: RequestLifetimes, fields: Vec, error_ty: Type, @@ -183,24 +144,14 @@ impl Request { let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] }); let fields = self.fields.iter().filter_map(RequestField::as_body_field); - // Though we don't track the difference between newtype body and body - // for lifetimes, the outer check and the macro failing if it encounters - // an illegal combination of field attributes, is enough to guarantee - // `body_lifetimes` correctness. - let lifetimes = &self.lifetimes.body; - let derive_deserialize = lifetimes.is_empty().then(|| quote! { #serde::Deserialize }); - quote! { /// Data in the request body. #[cfg(any(feature = "client", feature = "server"))] #[derive(Debug, #ruma_macros::_FakeDeriveRumaApi, #ruma_macros::_FakeDeriveSerde)] #[cfg_attr(feature = "client", derive(#serde::Serialize))] - #[cfg_attr( - feature = "server", - derive(#ruma_common::serde::Incoming, #derive_deserialize) - )] + #[cfg_attr(feature = "server", derive(#serde::Deserialize))] #serde_attr - struct RequestBody< #(#lifetimes),* > { #(#fields),* } + struct RequestBody { #(#fields),* } } }); @@ -215,19 +166,13 @@ impl Request { }; let request_query_struct = request_query_def.map(|def| { - let lifetimes = &self.lifetimes.query; - let derive_deserialize = lifetimes.is_empty().then(|| quote! { #serde::Deserialize }); - quote! { /// Data in the request's query string. #[cfg(any(feature = "client", feature = "server"))] #[derive(Debug, #ruma_macros::_FakeDeriveRumaApi, #ruma_macros::_FakeDeriveSerde)] #[cfg_attr(feature = "client", derive(#serde::Serialize))] - #[cfg_attr( - feature = "server", - derive(#ruma_common::serde::Incoming, #derive_deserialize) - )] - struct RequestQuery< #(#lifetimes),* > #def + #[cfg_attr(feature = "server", derive(#serde::Deserialize))] + struct RequestQuery #def } }); @@ -294,14 +239,6 @@ impl Request { )); } - // TODO when/if `&[(&str, &str)]` is supported remove this - if has_query_map_field && !self.lifetimes.query.is_empty() { - return Err(syn::Error::new_spanned( - &self.ident, - "Lifetimes are not allowed for query_map fields", - )); - } - let path_fields = self.path_fields().map(|f| f.ident.as_ref().unwrap().to_string()); let mut tests = quote! { #[::std::prelude::v1::test] diff --git a/crates/ruma-macros/src/api/request/incoming.rs b/crates/ruma-macros/src/api/request/incoming.rs index 9939b30d..e7a162f0 100644 --- a/crates/ruma-macros/src/api/request/incoming.rs +++ b/crates/ruma-macros/src/api/request/incoming.rs @@ -12,9 +12,8 @@ impl Request { let error_ty = &self.error_ty; - // FIXME: the rest of the field initializer expansions are gated `cfg(...)` - // except this one. If we get errors about missing fields in IncomingRequest for - // a path field look here. + // FIXME: the rest of the field initializer expansions are gated `cfg(...)` except this one. + // If we get errors about missing fields in Request for a path field look here. let (parse_request_path, path_vars) = if self.has_path_fields() { let path_vars: Vec<_> = self.path_fields().filter_map(|f| f.ident.as_ref()).collect(); @@ -56,10 +55,9 @@ impl Request { ); let parse = quote! { - let request_query: IncomingRequestQuery = - #ruma_common::serde::urlencoded::from_str( - &request.uri().query().unwrap_or("") - )?; + let request_query: RequestQuery = #ruma_common::serde::urlencoded::from_str( + &request.uri().query().unwrap_or("") + )?; #decls }; @@ -131,7 +129,7 @@ impl Request { let extract_body = self.has_body_fields().then(|| { quote! { - let request_body: IncomingRequestBody = { + let request_body: RequestBody = { let body = ::std::convert::AsRef::<[::std::primitive::u8]>::as_ref( request.body(), ); @@ -162,7 +160,7 @@ impl Request { quote! { #[automatically_derived] #[cfg(feature = "server")] - impl #ruma_common::api::IncomingRequest for IncomingRequest { + impl #ruma_common::api::IncomingRequest for Request { type EndpointError = #error_ty; type OutgoingResponse = Response; diff --git a/crates/ruma-macros/src/api/response.rs b/crates/ruma-macros/src/api/response.rs index 0ae57d00..531ac6e1 100644 --- a/crates/ruma-macros/src/api/response.rs +++ b/crates/ruma-macros/src/api/response.rs @@ -36,15 +36,8 @@ pub fn expand_response(attr: ResponseAttr, item: ItemStruct) -> TokenStream { quote! { #maybe_feature_error - #[derive( - Clone, - Debug, - #ruma_macros::Response, - #ruma_common::serde::Incoming, - #ruma_common::serde::_FakeDeriveSerde, - )] + #[derive(Clone, Debug, #ruma_macros::Response, #ruma_common::serde::_FakeDeriveSerde)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize, #ruma_macros::_FakeDeriveRumaApi)] #[ruma_api(error = #error_ty)] #item } diff --git a/crates/ruma-macros/src/api/util.rs b/crates/ruma-macros/src/api/util.rs index 284e8ca3..430f311e 100644 --- a/crates/ruma-macros/src/api/util.rs +++ b/crates/ruma-macros/src/api/util.rs @@ -1,10 +1,7 @@ //! Functions to aid the `Api::to_tokens` method. -use std::collections::BTreeSet; - use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -use syn::{visit::Visit, Lifetime, Type}; pub fn map_option_literal(ver: &Option) -> TokenStream { match ver { @@ -16,14 +13,3 @@ pub fn map_option_literal(ver: &Option) -> TokenStream { pub fn is_valid_endpoint_path(string: &str) -> bool { string.as_bytes().iter().all(|b| (0x21..=0x7E).contains(b)) } - -pub fn collect_lifetime_idents(lifetimes: &mut BTreeSet, ty: &Type) { - struct Visitor<'lt>(&'lt mut BTreeSet); - impl<'ast> Visit<'ast> for Visitor<'_> { - fn visit_lifetime(&mut self, lt: &'ast Lifetime) { - self.0.insert(lt.clone()); - } - } - - Visitor(lifetimes).visit_type(ty); -} diff --git a/crates/ruma-macros/src/lib.rs b/crates/ruma-macros/src/lib.rs index 6da62f5c..9eb4f931 100644 --- a/crates/ruma-macros/src/lib.rs +++ b/crates/ruma-macros/src/lib.rs @@ -44,7 +44,6 @@ use self::{ enum_as_ref_str::expand_enum_as_ref_str, enum_from_string::expand_enum_from_string, eq_as_ref_str::expand_partial_eq_as_ref_str, - incoming::expand_derive_incoming, ord_as_ref_str::{expand_ord_as_ref_str, expand_partial_ord_as_ref_str}, serialize_as_ref_str::expand_serialize_as_ref_str, }, @@ -261,19 +260,6 @@ pub fn user_id(input: TokenStream) -> TokenStream { output.into() } -/// Generating an 'Incoming' version of the type this derive macro is used on. -/// -/// This type will be a fully-owned version of the input type, using no lifetime generics. -/// -/// By default, the generated type will derive `Debug` and `serde::Deserialize`. To derive -/// additional traits, use `#[incoming_derive(ExtraDeriveMacro)]`. To disable the default derives, -/// use `#[incoming_derive(!Debug, !Deserialize)]`. -#[proc_macro_derive(Incoming, attributes(incoming_derive))] -pub fn derive_incoming(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - expand_derive_incoming(input).unwrap_or_else(syn::Error::into_compile_error).into() -} - /// Derive the `AsRef` trait for an enum. #[proc_macro_derive(AsRefStr, attributes(ruma_enum))] pub fn derive_enum_as_ref_str(input: TokenStream) -> TokenStream { diff --git a/crates/ruma-macros/src/serde.rs b/crates/ruma-macros/src/serde.rs index 9819856c..708461f7 100644 --- a/crates/ruma-macros/src/serde.rs +++ b/crates/ruma-macros/src/serde.rs @@ -8,7 +8,6 @@ pub mod display_as_ref_str; pub mod enum_as_ref_str; pub mod enum_from_string; pub mod eq_as_ref_str; -pub mod incoming; pub mod ord_as_ref_str; pub mod serialize_as_ref_str; mod util; diff --git a/crates/ruma-macros/src/serde/incoming.rs b/crates/ruma-macros/src/serde/incoming.rs deleted file mode 100644 index db25196a..00000000 --- a/crates/ruma-macros/src/serde/incoming.rs +++ /dev/null @@ -1,301 +0,0 @@ -use proc_macro2::{Span, TokenStream}; -use quote::{format_ident, quote}; -use syn::{ - parse::{Parse, ParseStream}, - parse_quote, - punctuated::Punctuated, - AngleBracketedGenericArguments, Attribute, Data, DeriveInput, GenericArgument, GenericParam, - Generics, Ident, ItemType, ParenthesizedGenericArguments, Path, PathArguments, Token, Type, - TypePath, TypeReference, TypeSlice, -}; - -use crate::util::import_ruma_common; - -pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result { - let ruma_common = import_ruma_common(); - - let mut found_lifetime = false; - match &mut ty_def.data { - Data::Union(_) => panic!("#[derive(Incoming)] does not support Union types"), - Data::Enum(e) => { - for var in &mut e.variants { - for field in &mut var.fields { - if strip_lifetimes(&mut field.ty, &ruma_common) { - found_lifetime = true; - } - } - } - } - Data::Struct(s) => { - for field in &mut s.fields { - if !matches!(field.vis, syn::Visibility::Public(_)) { - return Err(syn::Error::new_spanned(field, "All fields must be marked `pub`")); - } - if strip_lifetimes(&mut field.ty, &ruma_common) { - found_lifetime = true; - } - } - } - } - - let ident = format_ident!("Incoming{}", ty_def.ident, span = Span::call_site()); - - if !found_lifetime { - let doc = format!( - "Convenience type alias for [{}], for consistency with other [{ident}] types.", - &ty_def.ident - ); - - let mut type_alias: ItemType = parse_quote! { type X = Y; }; - type_alias.vis = ty_def.vis.clone(); - type_alias.ident = ident; - type_alias.generics = ty_def.generics.clone(); - type_alias.ty = - Box::new(TypePath { qself: None, path: ty_def.ident.clone().into() }.into()); - - return Ok(quote! { - #[doc = #doc] - #type_alias - }); - } - - let meta: Vec = ty_def - .attrs - .iter() - .filter(|attr| attr.path.is_ident("incoming_derive")) - .map(|attr| attr.parse_args()) - .collect::>()?; - - let mut derive_debug = true; - let mut derive_deserialize = true; - - let mut derives: Vec<_> = meta - .into_iter() - .flat_map(|m| m.derive_macs) - .filter_map(|derive_mac| match derive_mac { - DeriveMac::Regular(id) => Some(quote! { #id }), - DeriveMac::NegativeDebug => { - derive_debug = false; - None - } - DeriveMac::NegativeDeserialize => { - derive_deserialize = false; - None - } - }) - .collect(); - - if derive_debug { - derives.push(quote! { ::std::fmt::Debug }); - } - derives.push(if derive_deserialize { - quote! { #ruma_common::exports::serde::Deserialize } - } else { - quote! { #ruma_common::serde::_FakeDeriveSerde } - }); - - ty_def.attrs.retain(filter_input_attrs); - clean_generics(&mut ty_def.generics); - - let doc = format!("'Incoming' variant of [{}].", &ty_def.ident); - ty_def.ident = ident; - - Ok(quote! { - #[doc = #doc] - #[derive( #( #derives ),* )] - #ty_def - }) -} - -/// Keep any `cfg`, `cfg_attr`, `serde` or `non_exhaustive` attributes found and pass them to the -/// Incoming variant. -fn filter_input_attrs(attr: &Attribute) -> bool { - attr.path.is_ident("cfg") - || attr.path.is_ident("cfg_attr") - || attr.path.is_ident("serde") - || attr.path.is_ident("non_exhaustive") - || attr.path.is_ident("allow") -} - -fn clean_generics(generics: &mut Generics) { - generics.params = generics - .params - .clone() - .into_iter() - .filter(|param| !matches!(param, GenericParam::Lifetime(_))) - .collect(); -} - -fn strip_lifetimes(field_type: &mut Type, ruma_common: &TokenStream) -> bool { - match field_type { - // T<'a> -> IncomingT - // The IncomingT has to be declared by the user of this derive macro. - Type::Path(TypePath { path, .. }) => { - let mut has_lifetimes = false; - let mut is_lifetime_generic = false; - - for seg in &mut path.segments { - // strip generic lifetimes - match &mut seg.arguments { - PathArguments::AngleBracketed(AngleBracketedGenericArguments { - args, .. - }) => { - *args = args - .clone() - .into_iter() - .map(|mut ty| { - if let GenericArgument::Type(ty) = &mut ty { - if strip_lifetimes(ty, ruma_common) { - has_lifetimes = true; - }; - } - ty - }) - .filter(|arg| { - if let GenericArgument::Lifetime(_) = arg { - is_lifetime_generic = true; - false - } else { - true - } - }) - .collect(); - } - PathArguments::Parenthesized(ParenthesizedGenericArguments { - inputs, .. - }) => { - *inputs = inputs - .clone() - .into_iter() - .map(|mut ty| { - if strip_lifetimes(&mut ty, ruma_common) { - has_lifetimes = true; - }; - ty - }) - .collect(); - } - _ => {} - } - } - - // If a type has a generic lifetime parameter there must be an `Incoming` variant of - // that type. - if is_lifetime_generic { - if let Some(name) = path.segments.last_mut() { - let incoming_ty_ident = format_ident!("Incoming{}", name.ident); - name.ident = incoming_ty_ident; - } - } - - has_lifetimes || is_lifetime_generic - } - Type::Reference(TypeReference { elem, .. }) => { - let special_replacement = match &mut **elem { - Type::Path(ty) => { - let path = &ty.path; - let last_seg = path.segments.last().unwrap(); - - if last_seg.ident == "str" { - // &str -> String - Some(parse_quote! { ::std::string::String }) - } else if last_seg.ident == "RawJsonValue" { - Some(parse_quote! { ::std::boxed::Box<#path> }) - } else if last_seg.ident == "ClientSecret" - || last_seg.ident == "DeviceId" - || last_seg.ident == "DeviceKeyId" - || last_seg.ident == "DeviceSigningKeyId" - || last_seg.ident == "EventId" - || last_seg.ident == "KeyId" - || last_seg.ident == "MxcUri" - || last_seg.ident == "ServerName" - || last_seg.ident == "SessionId" - || last_seg.ident == "RoomAliasId" - || last_seg.ident == "RoomId" - || last_seg.ident == "RoomOrAliasId" - || last_seg.ident == "RoomName" - || last_seg.ident == "ServerSigningKeyId" - || last_seg.ident == "SigningKeyId" - || last_seg.ident == "TransactionId" - || last_seg.ident == "UserId" - { - let ident = format_ident!("Owned{}", last_seg.ident); - Some(parse_quote! { #ruma_common::#ident }) - } else { - None - } - } - // &[T] -> Vec - Type::Slice(TypeSlice { elem, .. }) => { - // Recursively strip the lifetimes of the slice's elements. - strip_lifetimes(&mut *elem, ruma_common); - Some(parse_quote! { Vec<#elem> }) - } - _ => None, - }; - - *field_type = match special_replacement { - Some(ty) => ty, - None => { - // Strip lifetimes of `elem`. - strip_lifetimes(elem, ruma_common); - // Replace reference with `elem`. - (**elem).clone() - } - }; - - true - } - Type::Tuple(syn::TypeTuple { elems, .. }) => { - let mut has_lifetime = false; - for elem in elems { - if strip_lifetimes(elem, ruma_common) { - has_lifetime = true; - } - } - has_lifetime - } - _ => false, - } -} - -pub struct Meta { - derive_macs: Vec, -} - -impl Parse for Meta { - fn parse(input: ParseStream<'_>) -> syn::Result { - Ok(Self { - derive_macs: Punctuated::<_, Token![,]>::parse_terminated(input)?.into_iter().collect(), - }) - } -} - -pub enum DeriveMac { - Regular(Path), - NegativeDebug, - NegativeDeserialize, -} - -impl Parse for DeriveMac { - fn parse(input: ParseStream<'_>) -> syn::Result { - if input.peek(Token![!]) { - let _: Token![!] = input.parse()?; - let mac: Ident = input.parse()?; - - if mac == "Debug" { - Ok(Self::NegativeDebug) - } else if mac == "Deserialize" { - Ok(Self::NegativeDeserialize) - } else { - Err(syn::Error::new_spanned( - mac, - "Negative incoming_derive can only be used for Debug and Deserialize", - )) - } - } else { - let mac = input.parse()?; - Ok(Self::Regular(mac)) - } - } -} diff --git a/crates/ruma-push-gateway-api/src/send_event_notification.rs b/crates/ruma-push-gateway-api/src/send_event_notification.rs index 62c60741..31b543f7 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification.rs @@ -13,8 +13,8 @@ pub mod v1 { events::RoomEventType, metadata, push::{PushFormat, Tweak}, - serde::{Incoming, StringEnum}, - EventId, RoomAliasId, RoomId, SecondsSinceUnixEpoch, UserId, + serde::StringEnum, + OwnedEventId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, SecondsSinceUnixEpoch, }; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; @@ -34,9 +34,9 @@ pub mod v1 { /// Request type for the `send_event_notification` endpoint. #[request] - pub struct Request<'a> { + pub struct Request { /// Information about the push notification - pub notification: Notification<'a>, + pub notification: Notification, } /// Response type for the `send_event_notification` endpoint. @@ -53,9 +53,9 @@ pub mod v1 { pub rejected: Vec, } - impl<'a> Request<'a> { + impl Request { /// Creates a new `Request` with the given notification. - pub fn new(notification: Notification<'a>) -> Self { + pub fn new(notification: Notification) -> Self { Self { notification } } } @@ -68,42 +68,42 @@ pub mod v1 { } /// Type for passing information about a push notification - #[derive(Clone, Debug, Default, Incoming, Serialize)] + #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - pub struct Notification<'a> { + pub struct Notification { /// The Matrix event ID of the event being notified about. /// /// Required if the notification is about a particular Matrix event. May be omitted for /// notifications that only contain updated badge counts. This ID can and should be used to /// detect duplicate notification requests. #[serde(skip_serializing_if = "Option::is_none")] - pub event_id: Option<&'a EventId>, + pub event_id: Option, /// The ID of the room in which this event occurred. /// /// Required if the notification relates to a specific Matrix event. #[serde(skip_serializing_if = "Option::is_none")] - pub room_id: Option<&'a RoomId>, + pub room_id: Option, /// The type of the event as in the event's `type` field. #[serde(rename = "type", skip_serializing_if = "Option::is_none")] - pub event_type: Option<&'a RoomEventType>, + pub event_type: Option, /// The sender of the event as in the corresponding event field. #[serde(skip_serializing_if = "Option::is_none")] - pub sender: Option<&'a UserId>, + pub sender: Option, /// The current display name of the sender in the room in which the event occurred. #[serde(skip_serializing_if = "Option::is_none")] - pub sender_display_name: Option<&'a str>, + pub sender_display_name: Option, /// The name of the room in which the event occurred. #[serde(skip_serializing_if = "Option::is_none")] - pub room_name: Option<&'a str>, + pub room_name: Option, /// An alias to display for the room in which the event occurred. #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias: Option<&'a RoomAliasId>, + pub room_alias: Option, /// Whether the user receiving the notification is the subject of a member event (i.e. the /// `state_key` of the member event is equal to the user's Matrix ID). @@ -122,7 +122,7 @@ pub mod v1 { /// /// The pusher may omit this if the event had no content or for any other reason. #[serde(skip_serializing_if = "Option::is_none")] - pub content: Option<&'a RawJsonValue>, + pub content: Option>, /// Current number of unacknowledged communications for the recipient user. /// @@ -131,12 +131,12 @@ pub mod v1 { pub counts: NotificationCounts, /// An array of devices that the notification should be sent to. - pub devices: &'a [Device], + pub devices: Vec, } - impl<'a> Notification<'a> { + impl Notification { /// Create a new notification for the given devices. - pub fn new(devices: &'a [Device]) -> Self { + pub fn new(devices: Vec) -> Self { Notification { devices, ..Default::default() } } } @@ -192,7 +192,7 @@ pub mod v1 { } /// Type for passing information about devices. - #[derive(Clone, Debug, Deserialize, Incoming, Serialize)] + #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Device { /// The `app_id` given when the pusher was created. @@ -412,10 +412,10 @@ pub mod v1 { ] }); - let eid = event_id!("$3957tyerfgewrf384"); - let rid = room_id!("!slw48wfj34rtnrf:example.com"); - let uid = user_id!("@exampleuser:matrix.org"); - let alias = room_alias_id!("#exampleroom:matrix.org"); + let eid = event_id!("$3957tyerfgewrf384").to_owned(); + let rid = room_id!("!slw48wfj34rtnrf:example.com").to_owned(); + let uid = user_id!("@exampleuser:matrix.org").to_owned(); + let alias = room_alias_id!("#exampleroom:matrix.org").to_owned(); let count = NotificationCounts { unread: uint!(2), ..NotificationCounts::default() }; @@ -434,14 +434,14 @@ pub mod v1 { "V2h5IG9uIGVhcnRoIGRpZCB5b3UgZGVjb2RlIHRoaXM/".into(), ) }; - let devices = &[device]; + let devices = vec![device]; let notice = Notification { event_id: Some(eid), room_id: Some(rid), - event_type: Some(&RoomEventType::RoomMessage), + event_type: Some(RoomEventType::RoomMessage), sender: Some(uid), - sender_display_name: Some("Major Tom"), + sender_display_name: Some("Major Tom".to_owned()), room_alias: Some(alias), content: Some(serde_json::from_str("{}").unwrap()), counts: count, diff --git a/crates/ruma/tests/outgoing.rs b/crates/ruma/tests/outgoing.rs deleted file mode 100644 index f49327f3..00000000 --- a/crates/ruma/tests/outgoing.rs +++ /dev/null @@ -1,57 +0,0 @@ -// This test should really be part of ruma_common::serde, but some tooling -// doesn't like cyclic dev-dependencies, which are required for this test to be -// moved there. - -#![allow(clippy::exhaustive_structs, clippy::redundant_allocation)] - -use ruma::{serde::Incoming, UserId}; - -#[allow(unused)] -pub struct Thing<'t, T> { - some: &'t str, - t: &'t T, -} - -#[derive(Debug)] -#[allow(dead_code)] -pub struct IncomingThing { - some: String, - t: T, -} - -#[allow(unused)] -#[derive(Copy, Clone, Debug, Incoming, serde::Serialize)] -#[serde(crate = "serde")] -pub struct OtherThing<'t> { - pub some: &'t str, - pub t: &'t [u8], -} - -#[derive(Incoming)] -#[incoming_derive(!Deserialize)] -#[non_exhaustive] -pub struct FakeRequest<'a, T> { - pub abc: &'a str, - pub thing: Thing<'a, T>, - pub device_id: &'a ::ruma_common::DeviceId, - pub user_id: &'a UserId, - pub bytes: &'a [u8], - pub recursive: &'a [Thing<'a, T>], - pub option: Option<&'a [u8]>, - pub depth: Option<&'a [(&'a str, &'a str)]>, - pub arc_type: std::sync::Arc<&'a ::ruma_common::ServerName>, - pub thing_ref: &'a Thing<'a, T>, - pub double_ref: &'a &'a u8, - pub triple_ref: &'a &'a &'a str, -} - -#[derive(Incoming)] -#[incoming_derive(!Deserialize)] -#[non_exhaustive] -pub enum EnumThing<'a, T> { - Abc(&'a str), - Stuff(Thing<'a, T>), - Boxy(&'a ::ruma_common::DeviceId), - Other(Option<&'a str>), - StructVar { stuff: &'a str, more: &'a ::ruma_common::ServerName }, -} diff --git a/examples/hello_isahc/src/main.rs b/examples/hello_isahc/src/main.rs index b8d23814..f7749225 100644 --- a/examples/hello_isahc/src/main.rs +++ b/examples/hello_isahc/src/main.rs @@ -3,14 +3,14 @@ use std::{env, process::exit}; use ruma::{ api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event}, events::room::message::RoomMessageEventContent, - RoomAliasId, TransactionId, + OwnedRoomAliasId, TransactionId, }; async fn hello_world( homeserver_url: String, username: &str, password: &str, - room_alias: &RoomAliasId, + room_alias: OwnedRoomAliasId, ) -> anyhow::Result<()> { let http_client = isahc::HttpClient::new()?; let client = @@ -18,11 +18,11 @@ async fn hello_world( client.log_in(username, password, None, Some("ruma-example-client")).await?; let room_id = client.send_request(get_alias::v3::Request::new(room_alias)).await?.room_id; - client.send_request(join_room_by_id::v3::Request::new(&room_id)).await?; + client.send_request(join_room_by_id::v3::Request::new(room_id.clone())).await?; client .send_request(send_message_event::v3::Request::new( - &room_id, - &TransactionId::new(), + room_id, + TransactionId::new(), &RoomMessageEventContent::text_plain("Hello World!"), )?) .await?; @@ -44,6 +44,5 @@ async fn main() -> anyhow::Result<()> { } }; - hello_world(homeserver_url, &username, &password, <&RoomAliasId>::try_from(room.as_str())?) - .await + hello_world(homeserver_url, &username, &password, room.try_into()?).await } diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs index dc7c3257..cdf715aa 100644 --- a/examples/hello_world/src/main.rs +++ b/examples/hello_world/src/main.rs @@ -3,7 +3,7 @@ use std::{env, process::exit}; use ruma::{ api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event}, events::room::message::RoomMessageEventContent, - RoomAliasId, TransactionId, + OwnedRoomAliasId, TransactionId, }; type HttpClient = ruma::client::http_client::HyperNativeTls; @@ -12,18 +12,18 @@ async fn hello_world( homeserver_url: String, username: &str, password: &str, - room_alias: &RoomAliasId, + room_alias: OwnedRoomAliasId, ) -> anyhow::Result<()> { let client = ruma::Client::builder().homeserver_url(homeserver_url).build::().await?; client.log_in(username, password, None, Some("ruma-example-client")).await?; let room_id = client.send_request(get_alias::v3::Request::new(room_alias)).await?.room_id; - client.send_request(join_room_by_id::v3::Request::new(&room_id)).await?; + client.send_request(join_room_by_id::v3::Request::new(room_id.clone())).await?; client .send_request(send_message_event::v3::Request::new( - &room_id, - &TransactionId::new(), + room_id, + TransactionId::new(), &RoomMessageEventContent::text_plain("Hello World!"), )?) .await?; @@ -45,6 +45,5 @@ async fn main() -> anyhow::Result<()> { } }; - hello_world(homeserver_url, &username, &password, <&RoomAliasId>::try_from(room.as_str())?) - .await + hello_world(homeserver_url, &username, &password, room.try_into()?).await } diff --git a/examples/joke_bot/src/main.rs b/examples/joke_bot/src/main.rs index d1caddda..ad13785b 100644 --- a/examples/joke_bot/src/main.rs +++ b/examples/joke_bot/src/main.rs @@ -13,7 +13,7 @@ use ruma::{ }, presence::PresenceState, serde::Raw, - OwnedUserId, RoomId, TransactionId, UserId, + OwnedRoomId, OwnedUserId, TransactionId, UserId, }; use serde_json::Value as JsonValue; use tokio::fs; @@ -63,11 +63,11 @@ async fn run() -> Result<(), Box> { let filter = FilterDefinition::ignore_all().into(); let initial_sync_response = matrix_client .send_request(assign!(sync_events::v3::Request::new(), { - filter: Some(&filter), + filter: Some(filter), })) .await?; let user_id = &config.username; - let not_senders = &[user_id.clone()]; + let not_senders = vec![user_id.clone()]; let filter = { let mut filter = FilterDefinition::empty(); filter.room.timeline.not_senders = not_senders; @@ -76,9 +76,9 @@ async fn run() -> Result<(), Box> { .into(); let mut sync_stream = Box::pin(matrix_client.sync( - Some(&filter), + Some(filter), initial_sync_response.next_batch, - &PresenceState::Online, + PresenceState::Online, Some(Duration::from_secs(30)), )); @@ -92,15 +92,16 @@ async fn run() -> Result<(), Box> { // Use a regular for loop for the messages within one room to handle them sequentially for e in &room_info.timeline.events { if let Err(err) = - handle_message(http_client, matrix_client, e, room_id, user_id).await + handle_message(http_client, matrix_client, e, room_id.to_owned(), user_id).await { eprintln!("failed to respond to message: {err}"); } } }); - let invite_futures = response.rooms.invite.keys().map(|room_id| async move { - if let Err(err) = handle_invitations(http_client, matrix_client, room_id).await { + let invite_futures = response.rooms.invite.into_keys().map(|room_id| async move { + if let Err(err) = handle_invitations(http_client, matrix_client, room_id.clone()).await + { eprintln!("failed to accept invitation for room {room_id}: {err}"); } }); @@ -146,7 +147,7 @@ async fn handle_message( http_client: &HttpClient, matrix_client: &MatrixClient, e: &Raw, - room_id: &RoomId, + room_id: OwnedRoomId, bot_user_id: &UserId, ) -> Result<(), Box> { if let Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage( @@ -168,7 +169,11 @@ async fn handle_message( let joke_content = RoomMessageEventContent::text_plain(joke); let txn_id = TransactionId::new(); - let req = send_message_event::v3::Request::new(room_id, &txn_id, &joke_content)?; + let req = send_message_event::v3::Request::new( + room_id.to_owned(), + txn_id, + &joke_content, + )?; // Do nothing if we can't send the message. let _ = matrix_client.send_request(req).await; } @@ -181,16 +186,16 @@ async fn handle_message( async fn handle_invitations( http_client: &HttpClient, matrix_client: &MatrixClient, - room_id: &RoomId, + room_id: OwnedRoomId, ) -> Result<(), Box> { println!("invited to {room_id}"); - matrix_client.send_request(join_room_by_id::v3::Request::new(room_id)).await?; + matrix_client.send_request(join_room_by_id::v3::Request::new(room_id.clone())).await?; let greeting = "Hello! My name is Mr. Bot! I like to tell jokes. Like this one: "; let joke = get_joke(http_client).await.unwrap_or_else(|_| "err... never mind.".to_owned()); let content = RoomMessageEventContent::text_plain(format!("{greeting}\n{joke}")); let txn_id = TransactionId::new(); - let message = send_message_event::v3::Request::new(room_id, &txn_id, &content)?; + let message = send_message_event::v3::Request::new(room_id, txn_id, &content)?; matrix_client.send_request(message).await?; Ok(()) } diff --git a/examples/message_log/src/main.rs b/examples/message_log/src/main.rs index c72599dc..fdfcfc31 100644 --- a/examples/message_log/src/main.rs +++ b/examples/message_log/src/main.rs @@ -27,14 +27,14 @@ async fn log_messages( let filter = FilterDefinition::ignore_all().into(); let initial_sync_response = client .send_request(assign!(sync_events::v3::Request::new(), { - filter: Some(&filter), + filter: Some(filter), })) .await?; let mut sync_stream = Box::pin(client.sync( None, initial_sync_response.next_batch, - &PresenceState::Online, + PresenceState::Online, Some(Duration::from_secs(30)), ));