From 557a5958776ef71daaa9e61cebd2d1eabd3280b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 23 Feb 2022 21:06:13 +0100 Subject: [PATCH] events: Move room::create::RoomType to ruma-common --- .../ruma-client-api/src/room/create_room.rs | 3 +- crates/ruma-common/src/lib.rs | 1 + crates/ruma-common/src/room.rs | 28 +++++++++++++++++++ crates/ruma-events/src/room/create.rs | 27 +----------------- 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 crates/ruma-common/src/room.rs diff --git a/crates/ruma-client-api/src/room/create_room.rs b/crates/ruma-client-api/src/room/create_room.rs index 10484382..0b2e69a9 100644 --- a/crates/ruma-client-api/src/room/create_room.rs +++ b/crates/ruma-client-api/src/room/create_room.rs @@ -7,9 +7,10 @@ pub mod v3 { use assign::assign; use ruma_api::ruma_api; + use ruma_common::room::RoomType; use ruma_events::{ room::{ - create::{PreviousRoom, RoomCreateEventContent, RoomType}, + create::{PreviousRoom, RoomCreateEventContent}, power_levels::RoomPowerLevelsEventContent, }, AnyInitialStateEvent, diff --git a/crates/ruma-common/src/lib.rs b/crates/ruma-common/src/lib.rs index ee6d5feb..84534d48 100644 --- a/crates/ruma-common/src/lib.rs +++ b/crates/ruma-common/src/lib.rs @@ -12,6 +12,7 @@ pub mod power_levels; pub mod presence; pub mod push; pub mod receipt; +pub mod room; pub mod thirdparty; mod time; pub mod to_device; diff --git a/crates/ruma-common/src/room.rs b/crates/ruma-common/src/room.rs new file mode 100644 index 00000000..4276236a --- /dev/null +++ b/crates/ruma-common/src/room.rs @@ -0,0 +1,28 @@ +//! Common types for rooms. + +use ruma_serde::StringEnum; + +use crate::PrivOwnedStr; + +/// An enum of possible room types. +/// +/// This type can hold an arbitrary string. To check for room types that are not available as a +/// documented variant here, use its string representation, obtained through `.as_str()`. +#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] +#[non_exhaustive] +pub enum RoomType { + /// Defines the room as a space. + #[ruma_enum(rename = "m.space")] + Space, + + /// Defines the room as a custom type. + #[doc(hidden)] + _Custom(PrivOwnedStr), +} + +impl RoomType { + /// Creates a string slice from this `RoomType`. + pub fn as_str(&self) -> &str { + self.as_ref() + } +} diff --git a/crates/ruma-events/src/room/create.rs b/crates/ruma-events/src/room/create.rs index ade5655c..22d60f77 100644 --- a/crates/ruma-events/src/room/create.rs +++ b/crates/ruma-events/src/room/create.rs @@ -2,13 +2,11 @@ //! //! [`m.room.create`]: https://spec.matrix.org/v1.2/client-server-api/#mroomcreate +use ruma_common::room::RoomType; use ruma_events_macros::EventContent; use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; -use ruma_serde::StringEnum; use serde::{Deserialize, Serialize}; -use crate::PrivOwnedStr; - /// The content of an `m.room.create` event. /// /// This is the first event in a room and cannot be changed. @@ -62,29 +60,6 @@ impl RoomCreateEventContent { } } -/// An enum of possible room types. -/// -/// This type can hold an arbitrary string. To check for formats that are not available as a -/// documented variant here, use its string representation, obtained through `.as_str()`. -#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] -#[non_exhaustive] -pub enum RoomType { - /// Defines the room as a space. - #[ruma_enum(rename = "m.space")] - Space, - - /// Defines the room as a custom type. - #[doc(hidden)] - _Custom(PrivOwnedStr), -} - -impl RoomType { - /// Creates a string slice from this `RoomType`. - pub fn as_str(&self) -> &str { - self.as_ref() - } -} - /// A reference to an old room replaced during a room version upgrade. #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]