events: Make all pub enums non_exhaustive

This commit is contained in:
Devin Ragotzy 2021-06-29 14:43:15 -07:00 committed by Jonas Platte
parent 74b6a4c9d8
commit db755f994e
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
17 changed files with 194 additions and 5 deletions

View File

@ -137,6 +137,7 @@ fn expand_any_with_deser(
#[derive(Clone, Debug, #serde::Serialize)] #[derive(Clone, Debug, #serde::Serialize)]
#[serde(untagged)] #[serde(untagged)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum #ident { pub enum #ident {
#( #(
#[doc = #events] #[doc = #events]
@ -380,6 +381,7 @@ fn expand_content_enum(
#[derive(Clone, Debug, #serde::Serialize)] #[derive(Clone, Debug, #serde::Serialize)]
#[serde(untagged)] #[serde(untagged)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum #ident { pub enum #ident {
#( #(
#[doc = #event_type_str] #[doc = #event_type_str]
@ -444,6 +446,7 @@ fn expand_content_enum(
#[derive(Clone, Debug, #serde::Serialize)] #[derive(Clone, Debug, #serde::Serialize)]
#[serde(untagged)] #[serde(untagged)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum #redacted_ident { pub enum #redacted_ident {
#( #(
#[doc = #event_type_str] #[doc = #event_type_str]
@ -591,6 +594,7 @@ fn expand_redacted_enum(
/// An enum that holds either regular un-redacted events or redacted events. /// An enum that holds either regular un-redacted events or redacted events.
#[derive(Clone, Debug, #serde::Serialize)] #[derive(Clone, Debug, #serde::Serialize)]
#[serde(untagged)] #[serde(untagged)]
#[allow(clippy::exhaustive_enums)]
pub enum #ident { pub enum #ident {
/// An un-redacted event. /// An un-redacted event.
Regular(#regular_enum_ident), Regular(#regular_enum_ident),

View File

@ -128,6 +128,7 @@ fn generate_enum(
/// This type can hold an arbitrary string. To check for events that are not available as a /// This type can hold an arbitrary string. To check for events that are not available as a
/// documented variant here, use its string representation, obtained through `.as_str()`. /// documented variant here, use its string representation, obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, #ruma_serde::StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, #ruma_serde::StringEnum)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum #ident { pub enum #ident {
#( #(
#[doc = #ev_type_strings] #[doc = #ev_type_strings]

View File

@ -30,8 +30,12 @@ impl SessionDescription {
} }
/// The type of VoIP session description. /// The type of VoIP session description.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum SessionDescriptionType { pub enum SessionDescriptionType {
/// An answer. /// An answer.
Answer, Answer,
@ -42,3 +46,10 @@ pub enum SessionDescriptionType {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl SessionDescriptionType {
/// Creates a string slice from this `SessionDescriptionType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -39,8 +39,12 @@ impl HangupEventContent {
/// This should not be provided when the user naturally ends or rejects the call. When there was an /// This should not be provided when the user naturally ends or rejects the call. When there was an
/// error in the call negotiation, this should be `ice_failed` for when ICE negotiation fails or /// error in the call negotiation, this should be `ice_failed` for when ICE negotiation fails or
/// `invite_timeout` for when the other party did not answer in time. /// `invite_timeout` for when the other party did not answer in time.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Reason { pub enum Reason {
/// ICE negotiation failure. /// ICE negotiation failure.
IceFailed, IceFailed,
@ -51,3 +55,10 @@ pub enum Reason {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl Reason {
/// Creates a string slice from this `Reason`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -139,7 +139,7 @@ macro_rules! room_ev_accessor {
} }
/// Any room event. /// Any room event.
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum AnyRoomEvent { pub enum AnyRoomEvent {
@ -164,7 +164,7 @@ impl AnyRoomEvent {
} }
/// Any sync room event (room event without a `room_id`, as returned in `/sync` responses) /// Any sync room event (room event without a `room_id`, as returned in `/sync` responses)
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum AnySyncRoomEvent { pub enum AnySyncRoomEvent {
@ -250,7 +250,7 @@ impl<'de> de::Deserialize<'de> for AnySyncRoomEvent {
} }
/// Any redacted room event. /// Any redacted room event.
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum AnyRedactedRoomEvent { pub enum AnyRedactedRoomEvent {
/// Any message event that has been redacted. /// Any message event that has been redacted.
@ -286,7 +286,7 @@ impl From<AnyRedactedRoomEvent> for AnyRoomEvent {
} }
/// Any redacted sync room event (room event without a `room_id`, as returned in `/sync` responses) /// Any redacted sync room event (room event without a `room_id`, as returned in `/sync` responses)
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum AnyRedactedSyncRoomEvent { pub enum AnyRedactedSyncRoomEvent {
/// Any sync message event that has been redacted. /// Any sync message event that has been redacted.

View File

@ -24,8 +24,12 @@ pub mod request;
pub mod start; pub mod start;
/// A hash algorithm. /// A hash algorithm.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum HashAlgorithm { pub enum HashAlgorithm {
/// The SHA256 hash algorithm. /// The SHA256 hash algorithm.
Sha256, Sha256,
@ -34,9 +38,20 @@ pub enum HashAlgorithm {
_Custom(String), _Custom(String),
} }
impl HashAlgorithm {
/// Creates a string slice from this `HashAlgorithm`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// A key agreement protocol. /// A key agreement protocol.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "kebab-case")] #[ruma_enum(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum KeyAgreementProtocol { pub enum KeyAgreementProtocol {
/// The [Curve25519](https://cr.yp.to/ecdh.html) key agreement protocol. /// The [Curve25519](https://cr.yp.to/ecdh.html) key agreement protocol.
Curve25519, Curve25519,
@ -48,9 +63,20 @@ pub enum KeyAgreementProtocol {
_Custom(String), _Custom(String),
} }
impl KeyAgreementProtocol {
/// Creates a string slice from this `KeyAgreementProtocol`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// A message authentication code algorithm. /// A message authentication code algorithm.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "kebab-case")] #[ruma_enum(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum MessageAuthenticationCode { pub enum MessageAuthenticationCode {
/// The HKDF-HMAC-SHA256 MAC. /// The HKDF-HMAC-SHA256 MAC.
HkdfHmacSha256, HkdfHmacSha256,
@ -62,9 +88,20 @@ pub enum MessageAuthenticationCode {
_Custom(String), _Custom(String),
} }
impl MessageAuthenticationCode {
/// Creates a string slice from this `MessageAuthenticationCode`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// A Short Authentication String method. /// A Short Authentication String method.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ShortAuthenticationString { pub enum ShortAuthenticationString {
/// The decimal method. /// The decimal method.
Decimal, Decimal,
@ -76,6 +113,13 @@ pub enum ShortAuthenticationString {
_Custom(String), _Custom(String),
} }
impl ShortAuthenticationString {
/// Creates a string slice from this `ShortAuthenticationString`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// A relation which associates an `m.key.verification.request` with another key verification event. /// A relation which associates an `m.key.verification.request` with another key verification event.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
@ -96,7 +140,11 @@ impl Relation {
} }
/// A Short Authentication String (SAS) verification method. /// A Short Authentication String (SAS) verification method.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum VerificationMethod { pub enum VerificationMethod {
/// The *m.sas.v1* verification method. /// The *m.sas.v1* verification method.
#[ruma_enum(rename = "m.sas.v1")] #[ruma_enum(rename = "m.sas.v1")]
@ -121,6 +169,13 @@ pub enum VerificationMethod {
_Custom(String), _Custom(String),
} }
impl VerificationMethod {
/// Creates a string slice from this `VerificationMethod`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::{from_value as from_json_value, json}; use serde_json::{from_value as from_json_value, json};

View File

@ -75,6 +75,7 @@ impl CancelEventContent {
/// obtained through `.as_str()`. /// obtained through `.as_str()`.
// FIXME: Add `m.foo_bar` as a naming scheme in StringEnum and remove rename attributes. // FIXME: Add `m.foo_bar` as a naming scheme in StringEnum and remove rename attributes.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum CancelCode { pub enum CancelCode {
/// The user cancelled the verification. /// The user cancelled the verification.
#[ruma_enum(rename = "m.user")] #[ruma_enum(rename = "m.user")]

View File

@ -418,6 +418,7 @@ pub enum EventKind {
/// to aid in deserializing redacted events. /// to aid in deserializing redacted events.
#[doc(hidden)] #[doc(hidden)]
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum HasDeserializeFields { pub enum HasDeserializeFields {
/// Deserialize the event's content, failing if invalid. /// Deserialize the event's content, failing if invalid.
True, True,

View File

@ -29,8 +29,12 @@ impl PolicyRuleEventContent {
} }
} }
/// Rules recommendations /// The possible actions that can be taken.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum Recommendation { pub enum Recommendation {
/// Entities affected by the rule should be banned from participation where possible. /// Entities affected by the rule should be banned from participation where possible.
#[ruma_enum(rename = "m.ban")] #[ruma_enum(rename = "m.ban")]

View File

@ -59,7 +59,11 @@ impl CreateEventContent {
} }
/// An enum of possible room types. /// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum RoomType { pub enum RoomType {
/// Defines the room as a space. /// Defines the room as a space.
#[ruma_enum(rename = "m.space")] #[ruma_enum(rename = "m.space")]
@ -69,6 +73,13 @@ pub enum RoomType {
_Custom(String), _Custom(String),
} }
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)]

View File

@ -29,8 +29,12 @@ impl GuestAccessEventContent {
} }
/// A policy for guest user access to a room. /// A policy for guest user access to a room.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum GuestAccess { pub enum GuestAccess {
/// Guests are allowed to join the room. /// Guests are allowed to join the room.
CanJoin, CanJoin,
@ -41,3 +45,10 @@ pub enum GuestAccess {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl GuestAccess {
/// Creates a string slice from this `GuestAccess`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -28,8 +28,12 @@ impl HistoryVisibilityEventContent {
} }
/// Who can see a room's history. /// Who can see a room's history.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum HistoryVisibility { pub enum HistoryVisibility {
/// Previous events are accessible to newly joined members from the point they were invited /// Previous events are accessible to newly joined members from the point they were invited
/// onwards. Events stop being accessible when the member's state changes to something other /// onwards. Events stop being accessible when the member's state changes to something other
@ -52,3 +56,10 @@ pub enum HistoryVisibility {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl HistoryVisibility {
/// Creates a string slice from this `HistoryVisibility`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -27,8 +27,12 @@ impl JoinRulesEventContent {
} }
/// The rule used for users wishing to join this room. /// The rule used for users wishing to join this room.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "lowercase")] #[ruma_enum(rename_all = "lowercase")]
#[non_exhaustive]
pub enum JoinRule { pub enum JoinRule {
/// A user who wishes to join the room must first receive an invite to the room from someone /// A user who wishes to join the room must first receive an invite to the room from someone
/// already inside of the room. /// already inside of the room.
@ -46,3 +50,10 @@ pub enum JoinRule {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl JoinRule {
/// Creates a string slice from this `JoinRule`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -105,8 +105,12 @@ impl MemberEventContent {
} }
/// The membership state of a user. /// The membership state of a user.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "lowercase")] #[ruma_enum(rename_all = "lowercase")]
#[non_exhaustive]
pub enum MembershipState { pub enum MembershipState {
/// The user is banned. /// The user is banned.
Ban, Ban,
@ -127,6 +131,13 @@ pub enum MembershipState {
_Custom(String), _Custom(String),
} }
impl MembershipState {
/// Creates a string slice from this `MembershipState`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// Information about a third party invitation. /// Information about a third party invitation.
#[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)]

View File

@ -142,6 +142,7 @@ impl MessageEventContent {
/// The content that is specific to each message type variant. /// The content that is specific to each message type variant.
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[serde(untagged)] #[serde(untagged)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum MessageType { pub enum MessageType {
/// An audio message. /// An audio message.
Audio(AudioMessageEventContent), Audio(AudioMessageEventContent),
@ -647,7 +648,11 @@ impl ServerNoticeMessageEventContent {
} }
/// Types of server notices. /// Types of server notices.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum ServerNoticeType { pub enum ServerNoticeType {
/// The server has exceeded some limit which requires the server administrator to intervene. /// The server has exceeded some limit which requires the server administrator to intervene.
#[ruma_enum(rename = "m.server_notice.usage_limit_reached")] #[ruma_enum(rename = "m.server_notice.usage_limit_reached")]
@ -657,9 +662,20 @@ pub enum ServerNoticeType {
_Custom(String), _Custom(String),
} }
impl ServerNoticeType {
/// Creates a string slice from this `ServerNoticeType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// Types of usage limits. /// Types of usage limits.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum LimitType { pub enum LimitType {
/// The server's number of active users in the last 30 days has exceeded the maximum. /// The server's number of active users in the last 30 days has exceeded the maximum.
/// ///
@ -671,11 +687,19 @@ pub enum LimitType {
_Custom(String), _Custom(String),
} }
impl LimitType {
/// Creates a string slice from this `LimitType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// The format for the formatted representation of a message body. /// The format for the formatted representation of a message body.
/// ///
/// This type can hold an arbitrary string. To check for formats that are not available as a /// 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()`. /// documented variant here, use its string representation, obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum MessageFormat { pub enum MessageFormat {
/// HTML. /// HTML.
#[ruma_enum(rename = "org.matrix.custom.html")] #[ruma_enum(rename = "org.matrix.custom.html")]

View File

@ -34,8 +34,12 @@ impl FeedbackEventContent {
} }
/// A type of feedback. /// A type of feedback.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum FeedbackType { pub enum FeedbackType {
/// Sent when a message is received. /// Sent when a message is received.
Delivered, Delivered,
@ -46,3 +50,10 @@ pub enum FeedbackType {
#[doc(hidden)] #[doc(hidden)]
_Custom(String), _Custom(String),
} }
impl FeedbackType {
/// Creates a string slice from this `FeedbackType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -42,8 +42,12 @@ impl RoomKeyRequestToDeviceEventContent {
} }
/// A new key request or a cancellation of a previous request. /// A new key request or a cancellation of a previous request.
///
/// 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)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Action { pub enum Action {
/// Request a key. /// Request a key.
Request, Request,
@ -56,6 +60,13 @@ pub enum Action {
_Custom(String), _Custom(String),
} }
impl Action {
/// Creates a string slice from this `Action`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// Information about a requested key. /// Information about a requested key.
#[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)]