Mark types in ruma_events::room::create as non_exhaustive

This commit is contained in:
Jonas Platte 2020-07-17 00:21:08 +02:00
parent c35af9c5ea
commit 80ab6f0190
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -14,6 +14,7 @@ pub type CreateEvent = StateEvent<CreateEventContent>;
/// The payload for `CreateEvent`. /// The payload for `CreateEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)] #[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)]
#[non_exhaustive]
#[ruma_event(type = "m.room.create")] #[ruma_event(type = "m.room.create")]
pub struct CreateEventContent { pub struct CreateEventContent {
/// The `user_id` of the room creator. This is set by the homeserver. /// The `user_id` of the room creator. This is set by the homeserver.
@ -37,8 +38,16 @@ pub struct CreateEventContent {
pub predecessor: Option<PreviousRoom>, pub predecessor: Option<PreviousRoom>,
} }
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. /// A reference to an old room replaced during a room version upgrade.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct PreviousRoom { pub struct PreviousRoom {
/// The ID of the old room. /// The ID of the old room.
pub room_id: RoomId, pub room_id: RoomId,
@ -47,6 +56,13 @@ pub struct PreviousRoom {
pub event_id: EventId, 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. /// Used to default the `room_version` field to room version 1.
fn default_room_version_id() -> RoomVersionId { fn default_room_version_id() -> RoomVersionId {
RoomVersionId::try_from("1").unwrap() RoomVersionId::try_from("1").unwrap()