Skip to content

Commit

Permalink
client-api: Make all pub enums non_exhaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 authored and jplatte committed Jul 2, 2021
1 parent 6bc4744 commit ae5f848
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 16 deletions.
1 change: 1 addition & 0 deletions crates/ruma-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl StdError for ResponseDeserializationError {}

/// An error was reported by the server (HTTP status code 4xx or 5xx)
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum ServerError<E> {
/// An error that is expected to happen under certain circumstances and
/// that has a well-defined structure
Expand Down
2 changes: 2 additions & 0 deletions crates/ruma-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ use error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError};

/// An enum to control whether an access token should be added to outgoing requests
#[derive(Clone, Copy, Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum SendAccessToken<'a> {
/// Add the given access token to the request only if the `METADATA` on the request requires it
IfRequired(&'a str),
Expand Down Expand Up @@ -370,6 +371,7 @@ pub trait IncomingNonAuthRequest: IncomingRequest {}

/// Authentication scheme used by the endpoint.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(clippy::exhaustive_enums)]
pub enum AuthScheme {
/// No authentication is performed.
None,
Expand Down
1 change: 1 addition & 0 deletions crates/ruma-client-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod kind_serde;

/// An enum for the error kind. Items may contain additional information.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorKind {
/// M_FORBIDDEN
Forbidden,
Expand Down
11 changes: 11 additions & 0 deletions crates/ruma-client-api/src/r0/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ impl<'a> IdentityServerInfo<'a> {
}

/// Possible values for deleting or unbinding 3PIDs.
///
/// 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, StringEnum)]
#[ruma_enum(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum ThirdPartyIdRemovalStatus {
/// Either the homeserver couldn't determine the right identity server to contact, or the
/// identity server refused the operation.
Expand All @@ -53,3 +57,10 @@ pub enum ThirdPartyIdRemovalStatus {
#[doc(hidden)]
_Custom(String),
}

impl ThirdPartyIdRemovalStatus {
/// Creates a string slice from this `ThirdPartyIdRemovalStatus`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
2 changes: 2 additions & 0 deletions crates/ruma-client-api/src/r0/account/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Response {
/// The kind of account being registered.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum RegistrationKind {
/// A guest account
///
Expand All @@ -129,6 +130,7 @@ impl Default for RegistrationKind {

/// The login type.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum LoginType {
/// An appservice-specific login type
#[serde(rename = "m.login.application_service")]
Expand Down
1 change: 1 addition & 0 deletions crates/ruma-client-api/src/r0/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl RoomKeyBackup {
/// The algorithm used for storing backups.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "algorithm", content = "auth_data")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum BackupAlgorithm {
/// `m.megolm_backup.v1.curve25519-aes-sha2` backup algorithm.
#[serde(rename = "m.megolm_backup.v1.curve25519-aes-sha2")]
Expand Down
13 changes: 12 additions & 1 deletion crates/ruma-client-api/src/r0/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ impl Default for RoomVersionsCapability {
}
}

/// The stability of a room version
/// The stability of a room version.
///
/// 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 RoomVersionStability {
/// Support for the given version is stable.
Stable,
Expand All @@ -175,6 +179,13 @@ pub enum RoomVersionStability {
_Custom(String),
}

impl RoomVersionStability {
/// Creates a string slice from this `RoomVersionStability`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

#[cfg(test)]
mod tests {
use std::borrow::Cow;
Expand Down
11 changes: 11 additions & 0 deletions crates/ruma-client-api/src/r0/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ use ruma_serde::{Outgoing, StringEnum};
use serde::Serialize;

/// Format to use for returned events.
///
/// 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 EventFormat {
/// Client format, as described in the Client API.
Client,
Expand All @@ -28,6 +32,13 @@ pub enum EventFormat {
_Custom(String),
}

impl EventFormat {
/// Creates a string slice from this `EventFormat`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

impl Default for EventFormat {
fn default() -> Self {
Self::Client
Expand Down
1 change: 1 addition & 0 deletions crates/ruma-client-api/src/r0/filter/lazy_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::{ser::SerializeStruct as _, Deserialize, Serialize, Serializer};
/// [lazy-loading]: https://matrix.org/docs/spec/client_server/r0.6.0#lazy-loading-room-members
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
#[serde(from = "LazyLoadJsonRepr")]
#[allow(clippy::exhaustive_enums)]
pub enum LazyLoadOptions {
/// Disables lazy-loading of membership events.
Disabled,
Expand Down
1 change: 1 addition & 0 deletions crates/ruma-client-api/src/r0/filter/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{

/// Options for filtering based on the presence of a URL.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[allow(clippy::exhaustive_enums)]
pub enum UrlFilter {
/// Includes only events with a url key in their content.
EventsWithUrl,
Expand Down
39 changes: 25 additions & 14 deletions crates/ruma-client-api/src/r0/media/get_content_thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@ use ruma_api::ruma_api;
use ruma_identifiers::{Error, MxcUri, ServerName};
use ruma_serde::StringEnum;

/// The desired resizing method.
#[derive(Clone, Debug, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
pub enum Method {
/// Crop the original to produce the requested image dimensions.
Crop,

/// Maintain the original aspect ratio of the source image.
Scale,

#[doc(hidden)]
_Custom(String),
}

ruma_api! {
metadata: {
description: "Get a thumbnail of content from the media store.",
Expand Down Expand Up @@ -98,3 +84,28 @@ impl Response {
Self { file, content_type: None }
}
}

/// The desired resizing 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, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Method {
/// Crop the original to produce the requested image dimensions.
Crop,

/// Maintain the original aspect ratio of the source image.
Scale,

#[doc(hidden)]
_Custom(String),
}

impl Method {
/// Creates a string slice from this `Method`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
11 changes: 11 additions & 0 deletions crates/ruma-client-api/src/r0/membership/get_member_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ impl Response {
}

/// The kind of membership events to filter for.
///
/// 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 MembershipEventFilter {
/// The user has joined.
Join,
Expand All @@ -82,6 +86,13 @@ pub enum MembershipEventFilter {
_Custom(String),
}

impl MembershipEventFilter {
/// Creates a string slice from this `MembershipEventFilter`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

#[cfg(all(test, feature = "server"))]
mod tests {
use matches::assert_matches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fn is_default_limit(val: &UInt) -> bool {

/// The direction to return events from.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_enums)]
pub enum Direction {
/// Return events backwards in time from the requested `from` token.
#[serde(rename = "b")]
Expand Down
22 changes: 22 additions & 0 deletions crates/ruma-client-api/src/r0/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ impl TryFrom<PushRule> for ConditionalPushRule {
}

/// The kinds of push rules that are available.
///
/// 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, PartialOrd, Ord, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum RuleKind {
/// User-configured rules that override all other kinds.
Override,
Expand All @@ -181,9 +185,20 @@ pub enum RuleKind {
_Custom(String),
}

impl RuleKind {
/// Creates a string slice from this `RuleKind`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

/// Which kind a pusher is.
///
/// 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 PusherKind {
/// A pusher that sends HTTP pokes.
Http,
Expand All @@ -194,3 +209,10 @@ pub enum PusherKind {
#[doc(hidden)]
_Custom(String),
}

impl PusherKind {
/// Creates a string slice from this `PusherKind`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
11 changes: 11 additions & 0 deletions crates/ruma-client-api/src/r0/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ pub mod upgrade_room;
use ruma_serde::StringEnum;

/// Whether or not a newly created room will be listed in the room directory.
///
/// 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 Visibility {
/// Indicates that the room will be shown in the published room list.
Public,
Expand All @@ -21,6 +25,13 @@ pub enum Visibility {
_Custom(String),
}

impl Visibility {
/// Creates a string slice from this `Visibility`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

impl Default for Visibility {
fn default() -> Self {
Self::Private
Expand Down
11 changes: 11 additions & 0 deletions crates/ruma-client-api/src/r0/room/create_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ impl Default for CreationContent {
}

/// A convenience parameter for setting a few default state events.
///
/// 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 RoomPreset {
/// `join_rules` is set to `invite` and `history_visibility` is set to `shared`.
PrivateChat,
Expand All @@ -210,3 +214,10 @@ pub enum RoomPreset {
#[doc(hidden)]
_Custom(String),
}

impl RoomPreset {
/// Creates a string slice from this `RoomPreset`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
23 changes: 23 additions & 0 deletions crates/ruma-client-api/src/r0/search/search_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ impl Grouping {
}

/// The key within events to use for this grouping.
///
/// 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, PartialOrd, Ord, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum GroupingKey {
/// `room_id`
RoomId,
Expand All @@ -249,6 +253,13 @@ pub enum GroupingKey {
_Custom(String),
}

impl GroupingKey {
/// Creates a string slice from this `GroupingKey`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

/// Requests that the server partitions the result set based on the provided list of keys.
#[derive(Clone, Default, Debug, Outgoing, Serialize)]
#[incoming_derive(Default)]
Expand All @@ -272,7 +283,11 @@ impl Groupings<'_> {
}

/// The keys to search for.
///
/// 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 SearchKeys {
/// content.body
#[ruma_enum(rename = "content.body")]
Expand All @@ -290,6 +305,13 @@ pub enum SearchKeys {
_Custom(String),
}

impl SearchKeys {
/// Creates a string slice from this `SearchKeys`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

/// The order in which to search for results.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
Expand Down Expand Up @@ -465,6 +487,7 @@ impl UserProfile {

/// Represents either a room or user ID for returning grouped search results.
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[allow(clippy::exhaustive_enums)]
pub enum RoomIdOrUserId {
/// Represents a room ID.
RoomId(RoomId),
Expand Down

0 comments on commit ae5f848

Please sign in to comment.