events: Move room::create::RoomType to ruma-common

This commit is contained in:
Kévin Commaille 2022-02-23 21:06:13 +01:00 committed by Jonas Platte
parent d987b80c56
commit 557a595877
4 changed files with 32 additions and 27 deletions

View File

@ -7,9 +7,10 @@ pub mod v3 {
use assign::assign; use assign::assign;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::room::RoomType;
use ruma_events::{ use ruma_events::{
room::{ room::{
create::{PreviousRoom, RoomCreateEventContent, RoomType}, create::{PreviousRoom, RoomCreateEventContent},
power_levels::RoomPowerLevelsEventContent, power_levels::RoomPowerLevelsEventContent,
}, },
AnyInitialStateEvent, AnyInitialStateEvent,

View File

@ -12,6 +12,7 @@ pub mod power_levels;
pub mod presence; pub mod presence;
pub mod push; pub mod push;
pub mod receipt; pub mod receipt;
pub mod room;
pub mod thirdparty; pub mod thirdparty;
mod time; mod time;
pub mod to_device; pub mod to_device;

View File

@ -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()
}
}

View File

@ -2,13 +2,11 @@
//! //!
//! [`m.room.create`]: https://spec.matrix.org/v1.2/client-server-api/#mroomcreate //! [`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_events_macros::EventContent;
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
use ruma_serde::StringEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
/// The content of an `m.room.create` event. /// The content of an `m.room.create` event.
/// ///
/// This is the first event in a room and cannot be changed. /// 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. /// A reference to an old room replaced during a room version upgrade.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]