diff --git a/crates/ruma-api/tests/manual_endpoint_impl.rs b/crates/ruma-api/tests/manual_endpoint_impl.rs index 7a810796..87edb4e7 100644 --- a/crates/ruma-api/tests/manual_endpoint_impl.rs +++ b/crates/ruma-api/tests/manual_endpoint_impl.rs @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize}; /// A request to create a new room alias. #[derive(Debug)] pub struct Request { - pub room_id: RoomId, // body + pub room_id: Box, // body pub room_alias: Box, // path } @@ -88,7 +88,7 @@ impl IncomingRequest for Request { #[derive(Debug, Serialize, Deserialize)] struct RequestBody { - room_id: RoomId, + room_id: Box, } /// The response to a request to create a new room alias. diff --git a/crates/ruma-appservice-api/src/directory/set_room_visibility.rs b/crates/ruma-appservice-api/src/directory/set_room_visibility.rs index 6419c687..f7e7d820 100644 --- a/crates/ruma-appservice-api/src/directory/set_room_visibility.rs +++ b/crates/ruma-appservice-api/src/directory/set_room_visibility.rs @@ -20,7 +20,7 @@ ruma_api! { /// Room ID of the room to add or remove from the directory. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: Box, /// Whether the room should be visible (public) in the directory or not (private). pub visibility: Visibility, diff --git a/crates/ruma-appservice-api/src/event/push_events/v1.rs b/crates/ruma-appservice-api/src/event/push_events/v1.rs index 0cd3869b..b199ff2a 100644 --- a/crates/ruma-appservice-api/src/event/push_events/v1.rs +++ b/crates/ruma-appservice-api/src/event/push_events/v1.rs @@ -68,7 +68,7 @@ impl IncomingRequest { #[derive(Debug, Deserialize)] struct EventDeHelper { - room_id: Option, + room_id: Option>, } let mut response = sync_events::Response::new(next_batch.into()); @@ -138,7 +138,7 @@ mod helper_tests { incoming_request.try_into_sync_response(txn_id).unwrap(); let response_rooms_join = - response.rooms.join.get(&room_id!("!roomid:room.com")).expect("joined room response"); + response.rooms.join.get(room_id!("!roomid:room.com")).expect("joined room response"); assert_eq!(response_rooms_join.timeline.events.len(), 2); } diff --git a/crates/ruma-client-api/src/r0/alias/get_alias.rs b/crates/ruma-client-api/src/r0/alias/get_alias.rs index 9b8beaf1..22533fd7 100644 --- a/crates/ruma-client-api/src/r0/alias/get_alias.rs +++ b/crates/ruma-client-api/src/r0/alias/get_alias.rs @@ -21,7 +21,7 @@ ruma_api! { response: { /// The room ID for this room alias. - pub room_id: RoomId, + pub room_id: Box, /// A list of servers that are aware of this room ID. pub servers: Vec>, @@ -39,7 +39,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room id and servers - pub fn new(room_id: RoomId, servers: Vec>) -> Self { + pub fn new(room_id: Box, servers: Vec>) -> Self { Self { room_id, servers } } } diff --git a/crates/ruma-client-api/src/r0/backup/add_backup_keys.rs b/crates/ruma-client-api/src/r0/backup/add_backup_keys.rs index 57e9c859..cc1758a7 100644 --- a/crates/ruma-client-api/src/r0/backup/add_backup_keys.rs +++ b/crates/ruma-client-api/src/r0/backup/add_backup_keys.rs @@ -26,7 +26,7 @@ ruma_api! { pub version: &'a str, /// A map from room IDs to session IDs to key data. - pub rooms: BTreeMap, + pub rooms: BTreeMap, RoomKeyBackup>, } response: { @@ -45,7 +45,7 @@ ruma_api! { impl<'a> Request<'a> { /// 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: &'a str, rooms: BTreeMap, RoomKeyBackup>) -> Self { Self { version, rooms } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs b/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs index 3bc4b2fd..ec02a48a 100644 --- a/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs +++ b/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs @@ -27,7 +27,7 @@ ruma_api! { response: { /// A map from room IDs to session IDs to key data. - pub rooms: BTreeMap, + pub rooms: BTreeMap, RoomKeyBackup>, } error: crate::Error @@ -42,7 +42,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room key backups. - pub fn new(rooms: BTreeMap) -> Self { + pub fn new(rooms: BTreeMap, RoomKeyBackup>) -> Self { Self { rooms } } } diff --git a/crates/ruma-client-api/src/r0/directory.rs b/crates/ruma-client-api/src/r0/directory.rs index 05e9ffce..cf3792ec 100644 --- a/crates/ruma-client-api/src/r0/directory.rs +++ b/crates/ruma-client-api/src/r0/directory.rs @@ -31,7 +31,7 @@ pub struct PublicRoomsChunk { pub num_joined_members: UInt, /// The ID of the room. - pub room_id: RoomId, + pub room_id: Box, /// The topic of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] @@ -68,7 +68,7 @@ impl PublicRoomsChunk { /// All other fields will be propagated with default values (an empty list of aliases, `None` /// for all `Option`al fields and `false` for all boolean fields), which should be overridden; /// the `assign!` macro from the `assign` crate can simplify this. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id, aliases: Vec::new(), diff --git a/crates/ruma-client-api/src/r0/filter.rs b/crates/ruma-client-api/src/r0/filter.rs index d4a34db0..70d8fbfe 100644 --- a/crates/ruma-client-api/src/r0/filter.rs +++ b/crates/ruma-client-api/src/r0/filter.rs @@ -63,7 +63,7 @@ pub struct RoomEventFilter<'a> { /// 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 [RoomId], + pub not_rooms: &'a [Box], /// The maximum number of events to return. #[serde(skip_serializing_if = "Option::is_none")] @@ -73,7 +73,7 @@ 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 [RoomId]>, + pub rooms: Option<&'a [Box]>, /// A list of sender IDs to exclude. /// @@ -186,14 +186,14 @@ 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 [RoomId], + pub not_rooms: &'a [Box], /// 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 [RoomId]>, + pub rooms: Option<&'a [Box]>, } impl<'a> RoomFilter<'a> { diff --git a/crates/ruma-client-api/src/r0/knock/knock_room.rs b/crates/ruma-client-api/src/r0/knock/knock_room.rs index 481326b0..a7318f52 100644 --- a/crates/ruma-client-api/src/r0/knock/knock_room.rs +++ b/crates/ruma-client-api/src/r0/knock/knock_room.rs @@ -32,7 +32,7 @@ ruma_api! { response: { /// The room that the user knocked on. - pub room_id: RoomId, + pub room_id: Box, } } @@ -45,7 +45,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room ID. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/r0/membership/join_room_by_id.rs b/crates/ruma-client-api/src/r0/membership/join_room_by_id.rs index 0c0036ca..eaa73a0b 100644 --- a/crates/ruma-client-api/src/r0/membership/join_room_by_id.rs +++ b/crates/ruma-client-api/src/r0/membership/join_room_by_id.rs @@ -33,7 +33,7 @@ ruma_api! { response: { /// The room that the user joined. - pub room_id: RoomId, + pub room_id: Box, } error: crate::Error @@ -53,7 +53,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room id. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/r0/membership/join_room_by_id_or_alias.rs b/crates/ruma-client-api/src/r0/membership/join_room_by_id_or_alias.rs index 39c74382..79090fc2 100644 --- a/crates/ruma-client-api/src/r0/membership/join_room_by_id_or_alias.rs +++ b/crates/ruma-client-api/src/r0/membership/join_room_by_id_or_alias.rs @@ -40,7 +40,7 @@ ruma_api! { response: { /// The room that the user joined. - pub room_id: RoomId, + pub room_id: Box, } error: crate::Error @@ -61,7 +61,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room ID. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/r0/membership/joined_rooms.rs b/crates/ruma-client-api/src/r0/membership/joined_rooms.rs index 6f4e5c1b..2248cc34 100644 --- a/crates/ruma-client-api/src/r0/membership/joined_rooms.rs +++ b/crates/ruma-client-api/src/r0/membership/joined_rooms.rs @@ -19,7 +19,7 @@ ruma_api! { response: { /// A list of the rooms the user is in, i.e. the ID of each room in /// which the user has joined membership. - pub joined_rooms: Vec, + pub joined_rooms: Vec>, } error: crate::Error @@ -34,7 +34,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given joined rooms. - pub fn new(joined_rooms: Vec) -> Self { + pub fn new(joined_rooms: Vec>) -> Self { Self { joined_rooms } } } diff --git a/crates/ruma-client-api/src/r0/message/get_message_events.rs b/crates/ruma-client-api/src/r0/message/get_message_events.rs index 1bcefc9d..3fe7f891 100644 --- a/crates/ruma-client-api/src/r0/message/get_message_events.rs +++ b/crates/ruma-client-api/src/r0/message/get_message_events.rs @@ -144,20 +144,20 @@ mod tests { #[test] fn serialize_some_room_event_filter() { let room_id = room_id!("!roomid:example.org"); - let rooms = &[room_id.clone()]; + let rooms = &[room_id.to_owned()]; let filter = RoomEventFilter { lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: true }, rooms: Some(rooms), not_rooms: &[ - room_id!("!room:example.org"), - room_id!("!room2:example.org"), - room_id!("!room3:example.org"), + 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()], ..Default::default() }; let req = Request { - room_id: &room_id, + room_id, from: "token", to: Some("token2"), dir: Direction::Backward, @@ -185,7 +185,7 @@ mod tests { fn serialize_none_room_event_filter() { let room_id = room_id!("!roomid:example.org"); let req = Request { - room_id: &room_id, + room_id, from: "token", to: Some("token2"), dir: Direction::Backward, @@ -206,7 +206,7 @@ mod tests { fn serialize_default_room_event_filter() { let room_id = room_id!("!roomid:example.org"); let req = Request { - room_id: &room_id, + room_id, from: "token", to: Some("token2"), dir: Direction::Backward, diff --git a/crates/ruma-client-api/src/r0/push/get_notifications.rs b/crates/ruma-client-api/src/r0/push/get_notifications.rs index b505ff5d..7a5a3304 100644 --- a/crates/ruma-client-api/src/r0/push/get_notifications.rs +++ b/crates/ruma-client-api/src/r0/push/get_notifications.rs @@ -88,7 +88,7 @@ pub struct Notification { pub read: bool, /// The ID of the room in which the event was posted. - pub room_id: RoomId, + pub room_id: Box, /// The time at which the event notification was sent. pub ts: MilliSecondsSinceUnixEpoch, @@ -101,7 +101,7 @@ impl Notification { actions: Vec, event: Raw, read: bool, - room_id: RoomId, + room_id: Box, ts: MilliSecondsSinceUnixEpoch, ) -> Self { Self { actions, event, profile_tag: None, read, room_id, ts } diff --git a/crates/ruma-client-api/src/r0/room/create_room.rs b/crates/ruma-client-api/src/r0/room/create_room.rs index 0166bb9f..efa94530 100644 --- a/crates/ruma-client-api/src/r0/room/create_room.rs +++ b/crates/ruma-client-api/src/r0/room/create_room.rs @@ -92,7 +92,7 @@ ruma_api! { response: { /// The created room's ID. - pub room_id: RoomId, + pub room_id: Box, } error: crate::Error @@ -107,7 +107,7 @@ impl Request<'_> { impl Response { /// Creates a new `Response` with the given room id. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id } } } diff --git a/crates/ruma-client-api/src/r0/room/upgrade_room.rs b/crates/ruma-client-api/src/r0/room/upgrade_room.rs index 309a0c9a..b76dc102 100644 --- a/crates/ruma-client-api/src/r0/room/upgrade_room.rs +++ b/crates/ruma-client-api/src/r0/room/upgrade_room.rs @@ -24,7 +24,7 @@ ruma_api! { response: { /// ID of the new room. - pub replacement_room: RoomId, + pub replacement_room: Box, } error: crate::Error @@ -39,7 +39,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room ID. - pub fn new(replacement_room: RoomId) -> Self { + pub fn new(replacement_room: Box) -> Self { Self { replacement_room } } } diff --git a/crates/ruma-client-api/src/r0/search/search_events.rs b/crates/ruma-client-api/src/r0/search/search_events.rs index d6c675ae..ca9e0567 100644 --- a/crates/ruma-client-api/src/r0/search/search_events.rs +++ b/crates/ruma-client-api/src/r0/search/search_events.rs @@ -373,7 +373,7 @@ pub struct ResultRoomEvents { /// /// This is included if the request had the `include_state` key set with a value of `true`. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub state: BTreeMap>>, + pub state: BTreeMap, Vec>>, /// List of words which should be highlighted, useful for stemming which may /// change the query terms. @@ -498,7 +498,7 @@ impl UserProfile { #[allow(clippy::exhaustive_enums)] pub enum RoomIdOrUserId { /// Represents a room ID. - RoomId(RoomId), + RoomId(Box), /// Represents a user ID. UserId(UserId), diff --git a/crates/ruma-client-api/src/r0/state/get_state_events_for_key.rs b/crates/ruma-client-api/src/r0/state/get_state_events_for_key.rs index 04ed89a1..497e2a42 100644 --- a/crates/ruma-client-api/src/r0/state/get_state_events_for_key.rs +++ b/crates/ruma-client-api/src/r0/state/get_state_events_for_key.rs @@ -123,7 +123,7 @@ impl ruma_api::IncomingRequest for IncomingRequest { let decoded = percent_encoding::percent_decode(path_segments[4].as_bytes()).decode_utf8()?; - RoomId::try_from(&*decoded)? + Box::::try_from(&*decoded)? }; let event_type = { diff --git a/crates/ruma-client-api/src/r0/state/send_state_event.rs b/crates/ruma-client-api/src/r0/state/send_state_event.rs index d9d28af0..af5c7943 100644 --- a/crates/ruma-client-api/src/r0/state/send_state_event.rs +++ b/crates/ruma-client-api/src/r0/state/send_state_event.rs @@ -149,7 +149,7 @@ impl ruma_api::IncomingRequest for IncomingRequest { let decoded = percent_encoding::percent_decode(path_segments[4].as_bytes()).decode_utf8()?; - RoomId::try_from(&*decoded)? + Box::::try_from(&*decoded)? }; let event_type = percent_encoding::percent_decode(path_segments[6].as_bytes()) diff --git a/crates/ruma-client-api/src/r0/sync/sync_events.rs b/crates/ruma-client-api/src/r0/sync/sync_events.rs index da295625..c37aefd0 100644 --- a/crates/ruma-client-api/src/r0/sync/sync_events.rs +++ b/crates/ruma-client-api/src/r0/sync/sync_events.rs @@ -162,20 +162,20 @@ impl<'a> From<&'a str> for Filter<'a> { pub struct Rooms { /// The rooms that the user has left or been banned from. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub leave: BTreeMap, + pub leave: BTreeMap, LeftRoom>, /// The rooms that the user has joined. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub join: BTreeMap, + pub join: BTreeMap, JoinedRoom>, /// The rooms that the user has been invited to. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub invite: BTreeMap, + pub invite: BTreeMap, InvitedRoom>, /// The rooms that the user has knocked on. #[cfg(feature = "unstable-pre-spec")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub knock: BTreeMap, + pub knock: BTreeMap, KnockedRoom>, } impl Rooms { diff --git a/crates/ruma-common/src/directory.rs b/crates/ruma-common/src/directory.rs index 8574e51c..6d9f4ae2 100644 --- a/crates/ruma-common/src/directory.rs +++ b/crates/ruma-common/src/directory.rs @@ -35,7 +35,7 @@ pub struct PublicRoomsChunk { pub num_joined_members: UInt, /// The ID of the room. - pub room_id: RoomId, + pub room_id: Box, /// The topic of the room, if any. #[serde(skip_serializing_if = "Option::is_none")] @@ -72,7 +72,7 @@ pub struct PublicRoomsChunkInit { pub num_joined_members: UInt, /// The ID of the room. - pub room_id: RoomId, + pub room_id: Box, /// Whether the room may be viewed by guest users without joining. pub world_readable: bool, diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index 883255ac..b0f5eb55 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -966,7 +966,7 @@ mod tests { let set = Ruleset::server_default(&user_id!("@jolly_jumper:server.name")); let context_one_to_one = &PushConditionRoomCtx { - room_id: room_id!("!dm:server.name"), + room_id: room_id!("!dm:server.name").to_owned(), member_count: 2_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), @@ -975,7 +975,7 @@ mod tests { }; let context_public_room = &PushConditionRoomCtx { - room_id: room_id!("!far_west:server.name"), + room_id: room_id!("!far_west:server.name").to_owned(), member_count: 100_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), @@ -1065,7 +1065,7 @@ mod tests { #[test] fn custom_ruleset_applies() { let context_one_to_one = &PushConditionRoomCtx { - room_id: room_id!("!dm:server.name"), + room_id: room_id!("!dm:server.name").to_owned(), member_count: 2_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), diff --git a/crates/ruma-common/src/push/condition.rs b/crates/ruma-common/src/push/condition.rs index c0fa0b5b..8ff0b3d3 100644 --- a/crates/ruma-common/src/push/condition.rs +++ b/crates/ruma-common/src/push/condition.rs @@ -116,7 +116,7 @@ impl PushCondition { #[allow(clippy::exhaustive_structs)] pub struct PushConditionRoomCtx { /// The ID of the room. - pub room_id: RoomId, + pub room_id: Box, /// The number of members in the room. pub member_count: UInt, @@ -484,7 +484,7 @@ mod tests { users_power_levels.insert(first_sender, 25.into()); let context = PushConditionRoomCtx { - room_id: room_id!("!room:server.name"), + room_id: room_id!("!room:server.name").to_owned(), member_count: 3_u8.into(), user_display_name: "Groovy Gorilla".into(), users_power_levels, diff --git a/crates/ruma-events-macros/src/event.rs b/crates/ruma-events-macros/src/event.rs index 82814e0e..87541da0 100644 --- a/crates/ruma-events-macros/src/event.rs +++ b/crates/ruma-events-macros/src/event.rs @@ -509,7 +509,7 @@ fn expand_sync_from_into_full( /// Convert this sync event into a full event, one with a room_id field. pub fn into_full_event( self, - room_id: #ruma_identifiers::RoomId, + room_id: ::std::boxed::Box<#ruma_identifiers::RoomId>, ) -> #full_struct #ty_gen { let Self { #( #fields, )* } = self; #full_struct { diff --git a/crates/ruma-events-macros/src/event_enum.rs b/crates/ruma-events-macros/src/event_enum.rs index b824219a..9656014b 100644 --- a/crates/ruma-events-macros/src/event_enum.rs +++ b/crates/ruma-events-macros/src/event_enum.rs @@ -256,7 +256,7 @@ fn expand_into_full_event( /// Convert this sync event into a full event (one with a `room_id` field). pub fn into_full_event( self, - room_id: #ruma_identifiers::RoomId + room_id: ::std::boxed::Box<#ruma_identifiers::RoomId>, ) -> #full { match self { #( diff --git a/crates/ruma-events/src/direct.rs b/crates/ruma-events/src/direct.rs index e931e9f3..45099efc 100644 --- a/crates/ruma-events/src/direct.rs +++ b/crates/ruma-events/src/direct.rs @@ -18,10 +18,10 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[allow(clippy::exhaustive_structs)] #[ruma_event(type = "m.direct", kind = GlobalAccountData)] -pub struct DirectEventContent(pub BTreeMap>); +pub struct DirectEventContent(pub BTreeMap>>); impl Deref for DirectEventContent { - type Target = BTreeMap>; + type Target = BTreeMap>>; fn deref(&self) -> &Self::Target { &self.0 diff --git a/crates/ruma-events/src/enums.rs b/crates/ruma-events/src/enums.rs index 758ab706..02e7195a 100644 --- a/crates/ruma-events/src/enums.rs +++ b/crates/ruma-events/src/enums.rs @@ -182,7 +182,7 @@ impl AnySyncRoomEvent { room_ev_accessor!(sender: &UserId); /// Converts `self` to an `AnyRoomEvent` by adding the given a room ID. - pub fn into_full_event(self, room_id: RoomId) -> AnyRoomEvent { + pub fn into_full_event(self, room_id: Box) -> AnyRoomEvent { match self { Self::Message(ev) => AnyRoomEvent::Message(ev.into_full_event(room_id)), Self::State(ev) => AnyRoomEvent::State(ev.into_full_event(room_id)), diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index 7f85edc8..e614bdf6 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -32,7 +32,7 @@ pub struct EphemeralRoomEvent { pub content: C, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, } /// An ephemeral room event without a `room_id`. @@ -61,7 +61,7 @@ pub struct MessageEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// Additional key-value pairs not signed by the homeserver. pub unsigned: Unsigned, @@ -108,7 +108,7 @@ pub struct RedactedMessageEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// Additional key-value pairs not signed by the homeserver. pub unsigned: RedactedUnsigned, @@ -155,7 +155,7 @@ pub struct StateEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// A unique key which defines the overwriting semantics for this piece of room state. /// @@ -252,7 +252,7 @@ pub struct RedactedStateEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// A unique key which defines the overwriting semantics for this piece of room state. /// @@ -335,5 +335,5 @@ pub struct DecryptedMegolmV1Event { pub content: C, /// The ID of the room associated with the event. - pub room_id: RoomId, + pub room_id: Box, } diff --git a/crates/ruma-events/src/forwarded_room_key.rs b/crates/ruma-events/src/forwarded_room_key.rs index 08a2a2c0..0d413f91 100644 --- a/crates/ruma-events/src/forwarded_room_key.rs +++ b/crates/ruma-events/src/forwarded_room_key.rs @@ -16,7 +16,7 @@ pub struct ToDeviceForwardedRoomKeyEventContent { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: RoomId, + pub room_id: Box, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, @@ -54,7 +54,7 @@ pub struct ToDeviceForwardedRoomKeyEventContentInit { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: RoomId, + pub room_id: Box, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, diff --git a/crates/ruma-events/src/pdu.rs b/crates/ruma-events/src/pdu.rs index acecfd28..a2af16d9 100644 --- a/crates/ruma-events/src/pdu.rs +++ b/crates/ruma-events/src/pdu.rs @@ -38,7 +38,7 @@ pub struct RoomV1Pdu { pub event_id: Box, /// The room this event belongs to. - pub room_id: RoomId, + pub room_id: Box, /// The user id of the user who sent this event. pub sender: UserId, @@ -97,7 +97,7 @@ pub struct RoomV1Pdu { #[allow(clippy::exhaustive_structs)] pub struct RoomV3Pdu { /// The room this event belongs to. - pub room_id: RoomId, + pub room_id: Box, /// The user id of the user who sent this event. pub sender: UserId, diff --git a/crates/ruma-events/src/policy/rule/room.rs b/crates/ruma-events/src/policy/rule/room.rs index 6cebd2c6..099bb83f 100644 --- a/crates/ruma-events/src/policy/rule/room.rs +++ b/crates/ruma-events/src/policy/rule/room.rs @@ -35,7 +35,7 @@ mod tests { event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), sender: user_id!("@example:example.org"), origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()), - room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org"), + room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org").to_owned(), state_key: "rule:#*:example.org".into(), prev_content: None, unsigned: Unsigned { diff --git a/crates/ruma-events/src/room/canonical_alias.rs b/crates/ruma-events/src/room/canonical_alias.rs index 2ca05894..4a767457 100644 --- a/crates/ruma-events/src/room/canonical_alias.rs +++ b/crates/ruma-events/src/room/canonical_alias.rs @@ -54,7 +54,7 @@ mod tests { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, - room_id: room_id!("!dummy:example.com"), + room_id: room_id!("!dummy:example.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned::default(), diff --git a/crates/ruma-events/src/room/create.rs b/crates/ruma-events/src/room/create.rs index 497c99ac..a611a453 100644 --- a/crates/ruma-events/src/room/create.rs +++ b/crates/ruma-events/src/room/create.rs @@ -87,7 +87,7 @@ impl RoomType { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PreviousRoom { /// The ID of the old room. - pub room_id: RoomId, + pub room_id: Box, /// The event ID of the last known event in the old room. pub event_id: Box, @@ -95,7 +95,7 @@ pub struct PreviousRoom { impl PreviousRoom { /// Creates a new `PreviousRoom` from the given room and event IDs. - pub fn new(room_id: RoomId, event_id: Box) -> Self { + pub fn new(room_id: Box, event_id: Box) -> Self { Self { room_id, event_id } } } diff --git a/crates/ruma-events/src/room/join_rules.rs b/crates/ruma-events/src/room/join_rules.rs index fe4300d8..2b03ae5a 100644 --- a/crates/ruma-events/src/room/join_rules.rs +++ b/crates/ruma-events/src/room/join_rules.rs @@ -172,7 +172,7 @@ pub enum AllowRule { #[cfg(feature = "unstable-pre-spec")] impl AllowRule { /// Constructs an `AllowRule` with membership of the room with the given id as its predicate. - pub fn room_membership(room_id: RoomId) -> Self { + pub fn room_membership(room_id: Box) -> Self { Self::RoomMembership(RoomMembership::new(room_id)) } } @@ -183,13 +183,13 @@ impl AllowRule { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomMembership { /// The id of the room which being a member of grants permission to join another room. - pub room_id: RoomId, + pub room_id: Box, } #[cfg(feature = "unstable-pre-spec")] impl RoomMembership { /// Constructs a new room membership rule for the given room id. - pub fn new(room_id: RoomId) -> Self { + pub fn new(room_id: Box) -> Self { Self { room_id } } } @@ -275,8 +275,8 @@ mod tests { JoinRule::Restricted(restricted) => assert_eq!( restricted.allow, &[ - AllowRule::room_membership(room_id!("!mods:example.org")), - AllowRule::room_membership(room_id!("!users:example.org")) + AllowRule::room_membership(room_id!("!mods:example.org").to_owned()), + AllowRule::room_membership(room_id!("!users:example.org").to_owned()) ] ), rule => panic!("Deserialized to wrong variant: {:?}", rule), diff --git a/crates/ruma-events/src/room/message/reply.rs b/crates/ruma-events/src/room/message/reply.rs index 882311ef..498e1aec 100644 --- a/crates/ruma-events/src/room/message/reply.rs +++ b/crates/ruma-events/src/room/message/reply.rs @@ -302,7 +302,7 @@ fn formatted_or_plain_body<'a>(formatted: &'a Option, body: &'a s mod tests { use std::convert::TryFrom; - use ruma_identifiers::{EventId, RoomId, UserId}; + use ruma_identifiers::{room_id, EventId, UserId}; use super::RoomMessageEvent; use crate::room::message::RoomMessageEventContent; @@ -316,7 +316,7 @@ mod tests { event_id: EventId::new(sender.server_name()), sender, origin_server_ts: ruma_common::MilliSecondsSinceUnixEpoch::now(), - room_id: RoomId::try_from("!n8f893n9:example.com").unwrap(), + room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: crate::Unsigned::new(), }), "> <@alice:example.com> multi\n> line" diff --git a/crates/ruma-events/src/room/name.rs b/crates/ruma-events/src/room/name.rs index 9b90aef2..d545e88e 100644 --- a/crates/ruma-events/src/room/name.rs +++ b/crates/ruma-events/src/room/name.rs @@ -44,7 +44,7 @@ mod tests { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned::default(), @@ -73,7 +73,7 @@ mod tests { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: Some(RoomNameEventContent { name: "The old name".try_into().ok() }), - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, diff --git a/crates/ruma-events/src/room/power_levels.rs b/crates/ruma-events/src/room/power_levels.rs index ebd10b4b..111cf386 100644 --- a/crates/ruma-events/src/room/power_levels.rs +++ b/crates/ruma-events/src/room/power_levels.rs @@ -182,7 +182,7 @@ mod tests { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: Unsigned::default(), sender: user_id!("@carl:example.com"), state_key: "".into(), @@ -241,7 +241,7 @@ mod tests { users_default: int!(42), notifications: assign!(NotificationPowerLevels::new(), { room: int!(42) }), }), - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, sender: user, state_key: "".into(), diff --git a/crates/ruma-events/src/room/redaction.rs b/crates/ruma-events/src/room/redaction.rs index a524b44e..6c829742 100644 --- a/crates/ruma-events/src/room/redaction.rs +++ b/crates/ruma-events/src/room/redaction.rs @@ -27,7 +27,7 @@ pub struct RoomRedactionEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// Additional key-value pairs not signed by the homeserver. pub unsigned: Unsigned, @@ -74,7 +74,7 @@ pub struct RedactedRoomRedactionEvent { pub origin_server_ts: MilliSecondsSinceUnixEpoch, /// The ID of the room associated with this event. - pub room_id: RoomId, + pub room_id: Box, /// Additional key-value pairs not signed by the homeserver. pub unsigned: RedactedUnsigned, diff --git a/crates/ruma-events/src/room/tombstone.rs b/crates/ruma-events/src/room/tombstone.rs index 02f5cd04..147aa58a 100644 --- a/crates/ruma-events/src/room/tombstone.rs +++ b/crates/ruma-events/src/room/tombstone.rs @@ -20,12 +20,12 @@ pub struct RoomTombstoneEventContent { pub body: String, /// The new room the client should be visiting. - pub replacement_room: RoomId, + pub replacement_room: Box, } impl RoomTombstoneEventContent { /// Creates a new `RoomTombstoneEventContent` with the given body and replacement room ID. - pub fn new(body: String, replacement_room: RoomId) -> Self { + pub fn new(body: String, replacement_room: Box) -> Self { Self { body, replacement_room } } } diff --git a/crates/ruma-events/src/room_key.rs b/crates/ruma-events/src/room_key.rs index 3bae54cc..07d63ef5 100644 --- a/crates/ruma-events/src/room_key.rs +++ b/crates/ruma-events/src/room_key.rs @@ -17,7 +17,7 @@ pub struct ToDeviceRoomKeyEventContent { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: RoomId, + pub room_id: Box, /// The ID of the session that the key is for. pub session_id: String, @@ -31,7 +31,7 @@ impl ToDeviceRoomKeyEventContent { /// and session key. pub fn new( algorithm: EventEncryptionAlgorithm, - room_id: RoomId, + room_id: Box, session_id: String, session_key: String, ) -> Self { @@ -52,7 +52,7 @@ mod tests { let ev = ToDeviceEvent { content: ToDeviceRoomKeyEventContent { algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, - room_id: room_id!("!testroomid:example.org"), + room_id: room_id!("!testroomid:example.org").to_owned(), session_id: "SessId".into(), session_key: "SessKey".into(), }, diff --git a/crates/ruma-events/src/room_key_request.rs b/crates/ruma-events/src/room_key_request.rs index 42ae5d9f..72450be8 100644 --- a/crates/ruma-events/src/room_key_request.rs +++ b/crates/ruma-events/src/room_key_request.rs @@ -75,7 +75,7 @@ pub struct RequestedKeyInfo { pub algorithm: EventEncryptionAlgorithm, /// The room where the key is used. - pub room_id: RoomId, + pub room_id: Box, /// The Curve25519 key of the device which initiated the session originally. pub sender_key: String, @@ -89,7 +89,7 @@ impl RequestedKeyInfo { /// ID. pub fn new( algorithm: EventEncryptionAlgorithm, - room_id: RoomId, + room_id: Box, sender_key: String, session_id: String, ) -> Self { diff --git a/crates/ruma-events/tests/custom.rs b/crates/ruma-events/tests/custom.rs index 7ad01e38..82c5b8f7 100644 --- a/crates/ruma-events/tests/custom.rs +++ b/crates/ruma-events/tests/custom.rs @@ -52,7 +52,7 @@ fn serialize_custom_message_event() { }, event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)), - room_id: room_id!("!room:room.com"), + room_id: room_id!("!room:room.com").to_owned(), sender: user_id!("@carl:example.com"), unsigned: Unsigned::default(), }; @@ -93,7 +93,7 @@ fn serialize_custom_state_event() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)), prev_content: None, - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned::default(), diff --git a/crates/ruma-events/tests/enums.rs b/crates/ruma-events/tests/enums.rs index c399729f..98eb9340 100644 --- a/crates/ruma-events/tests/enums.rs +++ b/crates/ruma-events/tests/enums.rs @@ -204,7 +204,7 @@ fn message_event_serialization() { content: RoomMessageEventContent::text_plain("test"), event_id: event_id!("$1234:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)), - room_id: room_id!("!roomid:example.com"), + room_id: room_id!("!roomid:example.com").to_owned(), sender: user_id!("@test:example.com"), unsigned: Unsigned::default(), }; @@ -284,7 +284,7 @@ fn alias_event_field_access() { from_json_value::(json_data.clone()), Ok(AnyRoomEvent::State(state_event)) if state_event.state_key() == "" - && state_event.room_id() == &room_id!("!room:room.com") + && state_event.room_id() == room_id!("!room:room.com") && state_event.event_id() == event_id!("$152037280074GZeOm:localhost") && state_event.sender() == &user_id!("@example:localhost") ); @@ -316,7 +316,7 @@ fn ephemeral_event_deserialization() { assert_matches!( from_json_value::(json_data), Ok(ephem @ AnyEphemeralRoomEvent::Typing(_)) - if ephem.room_id() == &room_id!("!jEsUZKDJdhlrceRyVU:example.org") + if ephem.room_id() == room_id!("!jEsUZKDJdhlrceRyVU:example.org") ); } diff --git a/crates/ruma-events/tests/ephemeral_event.rs b/crates/ruma-events/tests/ephemeral_event.rs index 0a60a676..dd833ef3 100644 --- a/crates/ruma-events/tests/ephemeral_event.rs +++ b/crates/ruma-events/tests/ephemeral_event.rs @@ -15,7 +15,7 @@ use ruma_events::{ fn ephemeral_serialize_typing() { let aliases_event = EphemeralRoomEvent { content: TypingEventContent::new(vec![user_id!("@carl:example.com")]), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), }; let actual = to_json_value(&aliases_event).unwrap(); @@ -63,7 +63,7 @@ fn ephemeral_serialize_receipt() { }, }, }), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), }; let actual = to_json_value(&aliases_event).unwrap(); diff --git a/crates/ruma-events/tests/event_enums.rs b/crates/ruma-events/tests/event_enums.rs index 19db9223..4a3b81fe 100644 --- a/crates/ruma-events/tests/event_enums.rs +++ b/crates/ruma-events/tests/event_enums.rs @@ -88,7 +88,7 @@ fn serialize_message_event() { ), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), unsigned: Unsigned::default(), }); diff --git a/crates/ruma-events/tests/message_event.rs b/crates/ruma-events/tests/message_event.rs index 1aad80bd..a9897a6c 100644 --- a/crates/ruma-events/tests/message_event.rs +++ b/crates/ruma-events/tests/message_event.rs @@ -34,7 +34,7 @@ fn message_serialize_sticker() { ), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), unsigned: Unsigned::default(), }; @@ -243,7 +243,7 @@ fn deserialize_message_then_convert_to_full() { let sync_ev: AnySyncMessageEvent = from_json_value(json_data).unwrap(); // Test conversion method - let full = sync_ev.into_full_event(rid); + let full = sync_ev.into_full_event(rid.to_owned()); let full_json = to_json_value(full).unwrap(); assert_matches!( diff --git a/crates/ruma-events/tests/pdu.rs b/crates/ruma-events/tests/pdu.rs index 750fc686..edd791cd 100644 --- a/crates/ruma-events/tests/pdu.rs +++ b/crates/ruma-events/tests/pdu.rs @@ -27,7 +27,7 @@ fn serialize_pdu_as_v1() { unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap()); let v1_pdu = RoomV1Pdu { - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), event_id: event_id!("$somejoinevent:matrix.org").to_owned(), sender: user_id!("@sender:example.com"), origin: "matrix.org".into(), @@ -94,7 +94,7 @@ fn serialize_pdu_as_v3() { unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap()); let v3_pdu = RoomV3Pdu { - room_id: room_id!("!n8f893n9:example.com"), + room_id: room_id!("!n8f893n9:example.com").to_owned(), sender: user_id!("@sender:example.com"), origin: "matrix.org".into(), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()), diff --git a/crates/ruma-events/tests/redaction.rs b/crates/ruma-events/tests/redaction.rs index 86652760..da57e9f0 100644 --- a/crates/ruma-events/tests/redaction.rs +++ b/crates/ruma-events/tests/redaction.rs @@ -31,7 +31,7 @@ fn serialize_redaction() { redacts: event_id!("$nomore:example.com").to_owned(), event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/room_message.rs b/crates/ruma-events/tests/room_message.rs index d625a6d9..579c07c4 100644 --- a/crates/ruma-events/tests/room_message.rs +++ b/crates/ruma-events/tests/room_message.rs @@ -42,7 +42,7 @@ fn serialization() { ))), event_id: event_id!("$143273582443PhrSn:example.org").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)), - room_id: room_id!("!testroomid:example.org"), + room_id: room_id!("!testroomid:example.org").to_owned(), sender: user_id!("@user:example.org"), unsigned: Unsigned::default(), }; diff --git a/crates/ruma-events/tests/state_event.rs b/crates/ruma-events/tests/state_event.rs index e35d608a..b0e43c86 100644 --- a/crates/ruma-events/tests/state_event.rs +++ b/crates/ruma-events/tests/state_event.rs @@ -44,7 +44,7 @@ fn serialize_aliases_with_prev_content() { prev_content: Some(RoomAliasesEventContent::new(vec![ room_alias_id!("#inner:localhost").to_owned() ])), - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned::default(), @@ -65,7 +65,7 @@ fn serialize_aliases_without_prev_content() { event_id: event_id!("$h29iv0s8:example.com").to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), prev_content: None, - room_id: room_id!("!roomid:room.com"), + room_id: room_id!("!roomid:room.com").to_owned(), sender: user_id!("@carl:example.com"), state_key: "".into(), unsigned: Unsigned::default(), diff --git a/crates/ruma-events/tests/to_device.rs b/crates/ruma-events/tests/to_device.rs index 2eba21d8..f077100c 100644 --- a/crates/ruma-events/tests/to_device.rs +++ b/crates/ruma-events/tests/to_device.rs @@ -8,7 +8,7 @@ fn serialization() { sender: user_id!("@example:example.org"), content: ToDeviceRoomKeyEventContent::new( EventEncryptionAlgorithm::MegolmV1AesSha2, - room_id!("!testroomid:example.org"), + room_id!("!testroomid:example.org").to_owned(), "SessId".into(), "SessKey".into(), ), diff --git a/crates/ruma-events/tests/ui/04-event-sanity-check.rs b/crates/ruma-events/tests/ui/04-event-sanity-check.rs index d4e40f6c..39182fd7 100644 --- a/crates/ruma-events/tests/ui/04-event-sanity-check.rs +++ b/crates/ruma-events/tests/ui/04-event-sanity-check.rs @@ -15,7 +15,7 @@ pub struct StateEvent { pub event_id: Box, pub sender: UserId, pub origin_server_ts: MilliSecondsSinceUnixEpoch, - pub room_id: RoomId, + pub room_id: Box, pub state_key: String, pub prev_content: Option, pub unsigned: Unsigned, diff --git a/crates/ruma-federation-api/src/query/get_room_information/v1.rs b/crates/ruma-federation-api/src/query/get_room_information/v1.rs index 8983babc..54ff9a3d 100644 --- a/crates/ruma-federation-api/src/query/get_room_information/v1.rs +++ b/crates/ruma-federation-api/src/query/get_room_information/v1.rs @@ -21,7 +21,7 @@ ruma_api! { response: { /// Room ID mapped to queried alias. - pub room_id: RoomId, + pub room_id: Box, /// An array of server names that are likely to hold the given room. pub servers: Vec>, @@ -37,7 +37,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room IDs and servers. - pub fn new(room_id: RoomId, servers: Vec>) -> Self { + pub fn new(room_id: Box, servers: Vec>) -> Self { Self { room_id, servers } } } diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs index 34406e07..5dade970 100644 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs +++ b/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs @@ -71,7 +71,7 @@ pub struct ThirdPartyInvite { pub mxid: UserId, /// The room ID the invite is valid for. - pub room_id: RoomId, + pub room_id: Box, /// The user ID that sent the invite. pub sender: UserId, @@ -85,7 +85,7 @@ impl ThirdPartyInvite { pub fn new( address: String, mxid: UserId, - room_id: RoomId, + room_id: Box, sender: UserId, signed: BTreeMap, BTreeMap>, ) -> Self { diff --git a/crates/ruma-federation-api/src/transactions/edu.rs b/crates/ruma-federation-api/src/transactions/edu.rs index 06ec15ab..47658949 100644 --- a/crates/ruma-federation-api/src/transactions/edu.rs +++ b/crates/ruma-federation-api/src/transactions/edu.rs @@ -133,12 +133,12 @@ impl PresenceUpdate { pub struct ReceiptContent { /// Receipts for a particular room. #[serde(flatten)] - pub receipts: BTreeMap, + pub receipts: BTreeMap, ReceiptMap>, } impl ReceiptContent { /// Creates a new `ReceiptContent`. - pub fn new(receipts: BTreeMap) -> Self { + pub fn new(receipts: BTreeMap, ReceiptMap>) -> Self { Self { receipts } } } @@ -182,7 +182,7 @@ impl ReceiptData { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct TypingContent { /// The room where the user's typing status has been updated. - pub room_id: RoomId, + pub room_id: Box, /// The user ID that has had their typing status changed. pub user_id: UserId, @@ -193,7 +193,7 @@ pub struct TypingContent { impl TypingContent { /// Creates a new `TypingContent`. - pub fn new(room_id: RoomId, user_id: UserId, typing: bool) -> Self { + pub fn new(room_id: Box, user_id: UserId, typing: bool) -> Self { Self { room_id, user_id, typing } } } @@ -401,7 +401,7 @@ mod test { assert_matches!( &edu, Edu::Receipt(ReceiptContent { receipts }) - if receipts.get(&room_id!("!some_room:example.org")).is_some() + if receipts.get(room_id!("!some_room:example.org")).is_some() ); assert_eq!(serde_json::to_value(&edu).unwrap(), json); diff --git a/crates/ruma-identifiers-macros/src/lib.rs b/crates/ruma-identifiers-macros/src/lib.rs index f34de542..a49e6c87 100644 --- a/crates/ruma-identifiers-macros/src/lib.rs +++ b/crates/ruma-identifiers-macros/src/lib.rs @@ -67,7 +67,7 @@ pub fn room_id(input: TokenStream) -> TokenStream { assert!(room_id::validate(&id.value()).is_ok(), "Invalid room_id"); let output = quote! { - <#dollar_crate::RoomId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() + <&#dollar_crate::RoomId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() }; output.into() diff --git a/crates/ruma-identifiers-validation/src/room_id.rs b/crates/ruma-identifiers-validation/src/room_id.rs index cb2fa3f0..476bc77e 100644 --- a/crates/ruma-identifiers-validation/src/room_id.rs +++ b/crates/ruma-identifiers-validation/src/room_id.rs @@ -1,7 +1,5 @@ -use std::num::NonZeroU8; +use crate::{validate_delimited_id, Error}; -use crate::{parse_id, Error}; - -pub fn validate(s: &str) -> Result { - parse_id(s, &['!']) +pub fn validate(s: &str) -> Result<(), Error> { + validate_delimited_id(s, &['!']) } diff --git a/crates/ruma-identifiers/src/room_id.rs b/crates/ruma-identifiers/src/room_id.rs index 731b2f26..12551d38 100644 --- a/crates/ruma-identifiers/src/room_id.rs +++ b/crates/ruma-identifiers/src/room_id.rs @@ -1,6 +1,6 @@ //! Matrix room identifiers. -use std::{convert::TryInto, fmt, num::NonZeroU8}; +use std::convert::TryInto; use crate::{EventId, MatrixToRef, ServerName}; @@ -13,21 +13,14 @@ use crate::{EventId, MatrixToRef, ServerName}; /// # use std::convert::TryFrom; /// # use ruma_identifiers::RoomId; /// assert_eq!( -/// RoomId::try_from("!n8f893n9:example.com").unwrap().as_ref(), +/// <&RoomId>::try_from("!n8f893n9:example.com").unwrap(), /// "!n8f893n9:example.com" /// ); /// ``` -#[derive(Clone)] -pub struct RoomId { - pub(crate) full_id: Box, - pub(crate) colon_idx: NonZeroU8, -} +#[repr(transparent)] +pub struct RoomId(str); -impl fmt::Debug for RoomId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.full_id.fmt(f) - } -} +opaque_identifier_validated!(RoomId, ruma_identifiers_validation::room_id::validate); impl RoomId { /// Attempts to generate a `RoomId` for the given origin server with a localpart consisting of @@ -35,22 +28,18 @@ impl RoomId { /// /// Fails if the given homeserver cannot be parsed as a valid host. #[cfg(feature = "rand")] - pub fn new(server_name: &ServerName) -> Self { - use crate::generate_localpart; - - let full_id = format!("!{}:{}", generate_localpart(18), server_name).into(); - - Self { full_id, colon_idx: NonZeroU8::new(19).unwrap() } + pub fn new(server_name: &ServerName) -> Box { + Self::from_owned(format!("!{}:{}", crate::generate_localpart(18), server_name).into()) } /// Returns the rooms's unique ID. pub fn localpart(&self) -> &str { - &self.full_id[1..self.colon_idx.get() as usize] + &self.as_str()[1..self.colon_idx()] } /// Returns the server name of the room ID. pub fn server_name(&self) -> &ServerName { - self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap() + self.as_str()[self.colon_idx() + 1..].try_into().unwrap() } /// Create a `matrix.to` reference for this room ID. @@ -71,28 +60,19 @@ impl RoomId { &'a self, via: impl IntoIterator, ) -> MatrixToRef<'a> { - MatrixToRef::new(&self.full_id, via.into_iter().collect()) + MatrixToRef::new(self.as_str(), via.into_iter().collect()) } /// Create a `matrix.to` reference for an event scoped under this room ID. pub fn matrix_to_event_url<'a>(&'a self, ev_id: &'a EventId) -> MatrixToRef<'a> { - MatrixToRef::event(&self.full_id, ev_id, Vec::new()) + MatrixToRef::event(self.as_str(), ev_id, Vec::new()) + } + + fn colon_idx(&self) -> usize { + self.as_str().find(':').unwrap() } } -/// Attempts to create a new Matrix room ID from a string representation. -/// -/// The string must include the leading ! sigil, the localpart, a literal colon, and a server name. -fn try_from(room_id: S) -> Result -where - S: AsRef + Into>, -{ - let colon_idx = ruma_identifiers_validation::room_id::validate(room_id.as_ref())?; - Ok(RoomId { full_id: room_id.into(), colon_idx }) -} - -common_impls!(RoomId, try_from, "a Matrix room ID"); - #[cfg(test)] mod tests { use std::convert::TryFrom; @@ -103,7 +83,7 @@ mod tests { #[test] fn valid_room_id() { assert_eq!( - RoomId::try_from("!29fhd83h92h0:example.com") + <&RoomId>::try_from("!29fhd83h92h0:example.com") .expect("Failed to create RoomId.") .as_ref(), "!29fhd83h92h0:example.com" @@ -113,7 +93,7 @@ mod tests { #[test] fn empty_localpart() { assert_eq!( - RoomId::try_from("!:example.com").expect("Failed to create RoomId.").as_ref(), + <&RoomId>::try_from("!:example.com").expect("Failed to create RoomId.").as_ref(), "!:example.com" ); } @@ -135,7 +115,7 @@ mod tests { fn serialize_valid_room_id() { assert_eq!( serde_json::to_string( - &RoomId::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.") + <&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.") ) .expect("Failed to convert RoomId to JSON."), r#""!29fhd83h92h0:example.com""# @@ -146,16 +126,16 @@ mod tests { #[test] fn deserialize_valid_room_id() { assert_eq!( - serde_json::from_str::(r#""!29fhd83h92h0:example.com""#) + serde_json::from_str::>(r#""!29fhd83h92h0:example.com""#) .expect("Failed to convert JSON to RoomId"), - RoomId::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.") + <&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.") ); } #[test] fn valid_room_id_with_explicit_standard_port() { assert_eq!( - RoomId::try_from("!29fhd83h92h0:example.com:443") + <&RoomId>::try_from("!29fhd83h92h0:example.com:443") .expect("Failed to create RoomId.") .as_ref(), "!29fhd83h92h0:example.com:443" @@ -165,7 +145,7 @@ mod tests { #[test] fn valid_room_id_with_non_standard_port() { assert_eq!( - RoomId::try_from("!29fhd83h92h0:example.com:5000") + <&RoomId>::try_from("!29fhd83h92h0:example.com:5000") .expect("Failed to create RoomId.") .as_ref(), "!29fhd83h92h0:example.com:5000" @@ -174,23 +154,26 @@ mod tests { #[test] fn missing_room_id_sigil() { - assert_eq!(RoomId::try_from("carl:example.com").unwrap_err(), Error::MissingLeadingSigil); + assert_eq!( + <&RoomId>::try_from("carl:example.com").unwrap_err(), + Error::MissingLeadingSigil + ); } #[test] fn missing_room_id_delimiter() { - assert_eq!(RoomId::try_from("!29fhd83h92h0").unwrap_err(), Error::MissingDelimiter); + assert_eq!(<&RoomId>::try_from("!29fhd83h92h0").unwrap_err(), Error::MissingDelimiter); } #[test] fn invalid_room_id_host() { - assert_eq!(RoomId::try_from("!29fhd83h92h0:/").unwrap_err(), Error::InvalidServerName); + assert_eq!(<&RoomId>::try_from("!29fhd83h92h0:/").unwrap_err(), Error::InvalidServerName); } #[test] fn invalid_room_id_port() { assert_eq!( - RoomId::try_from("!29fhd83h92h0:example.com:notaport").unwrap_err(), + <&RoomId>::try_from("!29fhd83h92h0:example.com:notaport").unwrap_err(), Error::InvalidServerName ); } diff --git a/crates/ruma-identifiers/src/room_id_or_room_alias_id.rs b/crates/ruma-identifiers/src/room_id_or_room_alias_id.rs index 40ed6f55..7d70fa32 100644 --- a/crates/ruma-identifiers/src/room_id_or_room_alias_id.rs +++ b/crates/ruma-identifiers/src/room_id_or_room_alias_id.rs @@ -63,11 +63,9 @@ impl RoomIdOrAliasId { /// Turn this `RoomIdOrAliasId` into `Either` #[cfg(feature = "either")] - pub fn into_either(self) -> either::Either> { + pub fn into_either(self) -> either::Either, Box> { match self.variant() { - Variant::RoomId => { - either::Either::Left(RoomId { full_id: self.full_id, colon_idx: self.colon_idx }) - } + Variant::RoomId => either::Either::Left(self.as_str().try_into().unwrap()), Variant::RoomAliasId => either::Either::Right(self.as_str().try_into().unwrap()), } } @@ -103,9 +101,9 @@ where common_impls!(RoomIdOrAliasId, try_from, "a Matrix room ID or room alias ID"); -impl From for RoomIdOrAliasId { - fn from(RoomId { full_id, colon_idx }: RoomId) -> Self { - Self { full_id, colon_idx } +impl From> for RoomIdOrAliasId { + fn from(room_id: Box) -> Self { + Self::try_from(room_id.as_str()).unwrap() } } @@ -115,24 +113,24 @@ impl From> for RoomIdOrAliasId { } } -impl TryFrom for RoomId { +impl TryFrom for Box { type Error = Box; - fn try_from(id: RoomIdOrAliasId) -> Result> { + fn try_from(id: RoomIdOrAliasId) -> Result, Box> { match id.variant() { - Variant::RoomId => Ok(RoomId { full_id: id.full_id, colon_idx: id.colon_idx }), + Variant::RoomId => Ok(id.as_str().try_into().unwrap()), Variant::RoomAliasId => Err(id.as_str().try_into().unwrap()), } } } impl TryFrom for Box { - type Error = RoomId; + type Error = Box; - fn try_from(id: RoomIdOrAliasId) -> Result, RoomId> { + fn try_from(id: RoomIdOrAliasId) -> Result, Box> { match id.variant() { Variant::RoomAliasId => Ok(id.as_str().try_into().unwrap()), - Variant::RoomId => Err(RoomId { full_id: id.full_id, colon_idx: id.colon_idx }), + Variant::RoomId => Err(id.as_str().try_into().unwrap()), } } } diff --git a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs index 50c2866a..00c77950 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs @@ -364,7 +364,7 @@ mod tests { let notice = Notification { event_id: Some(eid), - room_id: Some(&rid), + room_id: Some(rid), event_type: Some(&EventType::RoomMessage), sender: Some(&uid), sender_display_name: Some("Major Tom"), diff --git a/crates/ruma-serde-macros/src/outgoing.rs b/crates/ruma-serde-macros/src/outgoing.rs index 835bd141..1af077ab 100644 --- a/crates/ruma-serde-macros/src/outgoing.rs +++ b/crates/ruma-serde-macros/src/outgoing.rs @@ -268,6 +268,7 @@ fn strip_lifetimes(field_type: &mut Type) -> bool { || last_seg.ident == "SessionId" || last_seg.ident == "RawJsonValue" || last_seg.ident == "RoomAliasId" + || last_seg.ident == "RoomId" || last_seg.ident == "RoomName" { // The identifiers that need to be boxed `Box` since they are DST's. diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index 13453d46..12290ea7 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -29,7 +29,7 @@ use ruma_events::{ }, EventType, }; -use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; +use ruma_identifiers::{room_id, EventId, RoomId, RoomVersionId, UserId}; use ruma_state_res::{self as state_res, Error, Event, Result, StateMap}; use serde_json::{ json, @@ -71,7 +71,7 @@ fn resolution_shallow_auth_chain(c: &mut Criterion) { state_sets .iter() .map(|map| { - store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() + store.auth_event_ids(room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), @@ -135,7 +135,7 @@ fn resolve_deeper_event_set(c: &mut Criterion) { state_sets .iter() .map(|map| { - store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() + store.auth_event_ids(room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| inner.get(id).map(Arc::clone), @@ -355,8 +355,8 @@ fn ella() -> UserId { UserId::try_from("@ella:foo").unwrap() } -fn room_id() -> RoomId { - RoomId::try_from("!test:foo").unwrap() +fn room_id() -> &'static RoomId { + room_id!("!test:foo") } fn member_content_ban() -> Box { @@ -390,7 +390,7 @@ where Arc::new(StateEvent { event_id: id.try_into().unwrap(), rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id(), + room_id: room_id().to_owned(), sender, origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), state_key, diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 1e8f570c..8d51ec17 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -1044,7 +1044,7 @@ mod tests { state_sets .iter() .map(|map| { - store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() + store.auth_event_ids(room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), @@ -1148,7 +1148,7 @@ mod tests { state_sets .iter() .map(|map| { - store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() + store.auth_event_ids(room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index b595836d..9b83eae2 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -112,7 +112,7 @@ pub fn do_check( let auth_chain_sets = state_sets .iter() .map(|map| { - store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() + store.auth_event_ids(room_id(), map.values().cloned().collect()).unwrap() }) .collect(); @@ -367,7 +367,7 @@ pub fn zara() -> UserId { user_id!("@zara:foo") } -pub fn room_id() -> RoomId { +pub fn room_id() -> &'static RoomId { room_id!("!test:foo") } @@ -393,7 +393,7 @@ pub fn to_init_pdu_event( Arc::new(StateEvent { event_id: id.try_into().unwrap(), rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id(), + room_id: room_id().to_owned(), sender, origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), state_key, @@ -433,7 +433,7 @@ where Arc::new(StateEvent { event_id: id.try_into().unwrap(), rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id(), + room_id: room_id().to_owned(), sender, origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), state_key,