From 80ab6f019058d880153ce09be93f0e089253f066 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 17 Jul 2020 00:21:08 +0200 Subject: [PATCH] Mark types in ruma_events::room::create as non_exhaustive --- ruma-events/src/room/create.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ruma-events/src/room/create.rs b/ruma-events/src/room/create.rs index 725dd32b..453dda12 100644 --- a/ruma-events/src/room/create.rs +++ b/ruma-events/src/room/create.rs @@ -14,6 +14,7 @@ pub type CreateEvent = StateEvent; /// The payload for `CreateEvent`. #[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)] +#[non_exhaustive] #[ruma_event(type = "m.room.create")] pub struct CreateEventContent { /// The `user_id` of the room creator. This is set by the homeserver. @@ -37,8 +38,16 @@ pub struct CreateEventContent { pub predecessor: Option, } +impl CreateEventContent { + /// Creates a new `CreateEventContent` with the given creator. + pub fn new(creator: UserId) -> Self { + Self { creator, federate: true, room_version: default_room_version_id(), predecessor: None } + } +} + /// A reference to an old room replaced during a room version upgrade. #[derive(Clone, Debug, Deserialize, Serialize)] +#[non_exhaustive] pub struct PreviousRoom { /// The ID of the old room. pub room_id: RoomId, @@ -47,6 +56,13 @@ pub struct PreviousRoom { pub event_id: EventId, } +impl PreviousRoom { + /// Creates a new `PreviousRoom` from the given room and event IDs. + pub fn new(room_id: RoomId, event_id: EventId) -> Self { + Self { room_id, event_id } + } +} + /// Used to default the `room_version` field to room version 1. fn default_room_version_id() -> RoomVersionId { RoomVersionId::try_from("1").unwrap()