diff --git a/crates/ruma-appservice-api/src/event/push_events.rs b/crates/ruma-appservice-api/src/event/push_events.rs index 51c808d8..ed84bda3 100644 --- a/crates/ruma-appservice-api/src/event/push_events.rs +++ b/crates/ruma-appservice-api/src/event/push_events.rs @@ -7,7 +7,9 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.2/application-service-api/#put_matrixappv1transactionstxnid - use ruma_common::{api::ruma_api, events::AnyRoomEvent, serde::Raw, TransactionId}; + use ruma_common::{ + api::ruma_api, events::AnyRoomEvent, serde::Raw, OwnedTransactionId, TransactionId, + }; ruma_api! { metadata: { @@ -44,7 +46,7 @@ pub mod v1 { impl IncomingRequest { /// Creates an `IncomingRequest` with the given transaction ID and list of events. - pub fn new(txn_id: Box, events: Vec>) -> IncomingRequest { + pub fn new(txn_id: OwnedTransactionId, events: Vec>) -> IncomingRequest { IncomingRequest { txn_id, events } } diff --git a/crates/ruma-client-api/src/membership/invite_user.rs b/crates/ruma-client-api/src/membership/invite_user.rs index 7bb41b75..532653f5 100644 --- a/crates/ruma-client-api/src/membership/invite_user.rs +++ b/crates/ruma-client-api/src/membership/invite_user.rs @@ -91,7 +91,7 @@ pub mod v3 { json!({ "user_id": "@carl:example.org" }), ) .unwrap(); - let user_id = user_id!("@carl:example.org").to_owned(); + let user_id = user_id!("@carl:example.org").into(); let recipient = IncomingInvitationRecipient::UserId { user_id }; assert_eq!(incoming, recipient); } 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 079a1053..5e375271 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 @@ -9,7 +9,7 @@ pub mod v3 { api::ruma_api, events::{AnyStateEventContent, StateEventType}, serde::{Incoming, Raw}, - RoomId, + OwnedRoomId, RoomId, }; ruma_api! { @@ -144,7 +144,7 @@ pub mod v3 { { // FIXME: find a way to make this if-else collapse with serde recognizing trailing // Option - let (room_id, event_type, state_key): (Box, StateEventType, String) = + let (room_id, event_type, state_key): (OwnedRoomId, StateEventType, String) = if path_args.len() == 3 { serde::Deserialize::deserialize(serde::de::value::SeqDeserializer::< _, 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 18699eac..35b87ff4 100644 --- a/crates/ruma-client-api/src/state/send_state_event.rs +++ b/crates/ruma-client-api/src/state/send_state_event.rs @@ -9,7 +9,7 @@ pub mod v3 { api::ruma_api, events::{AnyStateEventContent, StateEventContent, StateEventType}, serde::{Incoming, Raw}, - EventId, RoomId, + EventId, OwnedRoomId, RoomId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -174,7 +174,7 @@ pub mod v3 { { // FIXME: find a way to make this if-else collapse with serde recognizing trailing // Option - let (room_id, event_type, state_key): (Box, StateEventType, String) = + let (room_id, event_type, state_key): (OwnedRoomId, StateEventType, String) = if path_args.len() == 3 { serde::Deserialize::deserialize(serde::de::value::SeqDeserializer::< _, diff --git a/crates/ruma-macros/src/serde/incoming.rs b/crates/ruma-macros/src/serde/incoming.rs index 096ef053..ea57d5db 100644 --- a/crates/ruma-macros/src/serde/incoming.rs +++ b/crates/ruma-macros/src/serde/incoming.rs @@ -20,7 +20,7 @@ pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result { for var in &mut e.variants { for field in &mut var.fields { - if strip_lifetimes(&mut field.ty) { + if strip_lifetimes(&mut field.ty, &ruma_common) { found_lifetime = true; } } @@ -31,7 +31,7 @@ pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result bool { +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. @@ -137,7 +137,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { .into_iter() .map(|mut ty| { if let GenericArgument::Type(ty) = &mut ty { - if strip_lifetimes(ty) { + if strip_lifetimes(ty, ruma_common) { has_lifetimes = true; }; } @@ -160,7 +160,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { .clone() .into_iter() .map(|mut ty| { - if strip_lifetimes(&mut ty) { + if strip_lifetimes(&mut ty, ruma_common) { has_lifetimes = true; }; ty @@ -191,6 +191,8 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { 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" @@ -200,7 +202,6 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { || last_seg.ident == "MxcUri" || last_seg.ident == "ServerName" || last_seg.ident == "SessionId" - || last_seg.ident == "RawJsonValue" || last_seg.ident == "RoomAliasId" || last_seg.ident == "RoomId" || last_seg.ident == "RoomOrAliasId" @@ -210,8 +211,8 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { || last_seg.ident == "TransactionId" || last_seg.ident == "UserId" { - // The identifiers that need to be boxed `Box` since they are DST's. - Some(parse_quote! { ::std::boxed::Box<#path> }) + let ident = format_ident!("Owned{}", last_seg.ident); + Some(parse_quote! { #ruma_common::#ident }) } else { None } @@ -219,7 +220,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { // &[T] -> Vec Type::Slice(TypeSlice { elem, .. }) => { // Recursively strip the lifetimes of the slice's elements. - strip_lifetimes(&mut *elem); + strip_lifetimes(&mut *elem, ruma_common); Some(parse_quote! { Vec<#elem> }) } _ => None, @@ -229,7 +230,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { Some(ty) => ty, None => { // Strip lifetimes of `elem`. - strip_lifetimes(elem); + strip_lifetimes(elem, ruma_common); // Replace reference with `elem`. (**elem).clone() } @@ -240,7 +241,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { Type::Tuple(syn::TypeTuple { elems, .. }) => { let mut has_lifetime = false; for elem in elems { - if strip_lifetimes(elem) { + if strip_lifetimes(elem, ruma_common) { has_lifetime = true; } }