common: Make all pub enums non_exhaustive

This commit is contained in:
Devin Ragotzy 2021-06-29 14:41:07 -07:00 committed by Jonas Platte
parent 28e3d0f277
commit 74b6a4c9d8
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
8 changed files with 59 additions and 0 deletions

View File

@ -3,7 +3,11 @@
use ruma_serde::StringEnum;
/// Access token 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 TokenType {
/// Bearer token type
Bearer,
@ -11,3 +15,10 @@ pub enum TokenType {
#[doc(hidden)]
_Custom(String),
}
impl TokenType {
/// Creates a string slice from this `TokenType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -5,8 +5,12 @@
use ruma_serde::StringEnum;
/// A description of a user's connectivity and availability for chat.
///
/// 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)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PresenceState {
/// Disconnected from the service.
Offline,
@ -32,3 +36,10 @@ impl Default for &'_ PresenceState {
&PresenceState::Online
}
}
impl PresenceState {
/// Creates a string slice from this `PresenceState`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -411,9 +411,13 @@ impl PusherData {
/// A special format that the homeserver should use when sending notifications to a Push Gateway.
/// Currently, only "event_id_only" is supported as of [Push Gateway API r0.1.1][spec].
///
/// 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()`.
///
/// [spec]: https://matrix.org/docs/spec/push_gateway/r0.1.1#homeserver-behaviour
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PushFormat {
/// Require the homeserver to only send a reduced set of fields in the push.
EventIdOnly,
@ -422,6 +426,13 @@ pub enum PushFormat {
_Custom(String),
}
impl PushFormat {
/// Creates a string slice from this `PushFormat`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

View File

@ -11,6 +11,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
///
/// Used by `RoomMemberCountIs`. Defaults to `==`.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(clippy::exhaustive_enums)]
pub enum ComparisonOperator {
/// Equals
Eq,

View File

@ -7,6 +7,7 @@ use super::{
/// The kinds of push rules that are available.
#[derive(Clone, Debug)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum AnyPushRule {
/// Rules that override all other kinds.
Override(ConditionalPushRule),
@ -114,6 +115,7 @@ impl IntoIterator for Ruleset {
/// Reference to any kind of push rule.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum AnyPushRuleRef<'a> {
/// Rules that override all other kinds.
Override(&'a ConditionalPushRule),

View File

@ -3,7 +3,11 @@
use ruma_serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum};
/// The type of receipt.
///
/// 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, PartialOrdAsRefStr, OrdAsRefStr, PartialEqAsRefStr, Eq, StringEnum)]
#[non_exhaustive]
pub enum ReceiptType {
/// m.read
#[ruma_enum(rename = "m.read")]
@ -12,3 +16,10 @@ pub enum ReceiptType {
#[doc(hidden)]
_Custom(String),
}
impl ReceiptType {
/// Creates a string slice from this `ReceiptType`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

View File

@ -211,8 +211,12 @@ impl User {
}
/// The medium of a third party identifier.
///
/// 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)]
#[ruma_enum(rename_all = "lowercase")]
#[non_exhaustive]
pub enum Medium {
/// Email address identifier
Email,
@ -224,6 +228,13 @@ pub enum Medium {
_Custom(String),
}
impl Medium {
/// Creates a string slice from this `Medium`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
/// An identifier external to Matrix.
///
/// To create an instance of this type, first create a `ThirdPartyIdentifierInit` and convert it to

View File

@ -15,6 +15,7 @@ use serde::{
/// Represents one or all of a user's devices.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[allow(clippy::exhaustive_enums)]
pub enum DeviceIdOrAllDevices {
/// Represents a device Id for one of a user's devices.
DeviceId(DeviceIdBox),