client-api: Make all pub enums non_exhaustive
This commit is contained in:
parent
1489b5e1f1
commit
ab3d48b576
@ -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
|
||||
|
@ -215,6 +215,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),
|
||||
@ -371,6 +372,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,
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
///
|
||||
@ -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")]
|
||||
|
@ -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")]
|
||||
|
@ -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,
|
||||
@ -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;
|
||||
|
@ -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,
|
||||
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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.",
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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;
|
||||
|
@ -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")]
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,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,
|
||||
@ -22,6 +26,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
|
||||
|
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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)]
|
||||
@ -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")]
|
||||
@ -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)]
|
||||
@ -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),
|
||||
|
@ -78,6 +78,7 @@ impl Response {
|
||||
/// Identification information for the user.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||
#[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum UserIdentifier<'a> {
|
||||
/// Either a fully qualified Matrix user ID, or just the localpart (as part of the 'identifier'
|
||||
/// field).
|
||||
@ -106,6 +107,7 @@ pub enum UserIdentifier<'a> {
|
||||
/// The authentication mechanism.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum LoginInfo<'a> {
|
||||
/// An identifier and password are supplied to authenticate.
|
||||
#[serde(rename = "m.login.password")]
|
||||
|
@ -134,6 +134,7 @@ impl Response {
|
||||
/// A filter represented either as its full JSON definition or the ID of a saved filter.
|
||||
#[derive(Clone, Debug, Outgoing, Serialize)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[serde(untagged)]
|
||||
pub enum Filter<'a> {
|
||||
// The filter definition needs to be (de)serialized twice because it is a URL-encoded JSON
|
||||
@ -146,8 +147,8 @@ pub enum Filter<'a> {
|
||||
// FilterDefinition is the first variant, JSON decoding is attempted first which is almost
|
||||
// functionally equivalent to looking at whether the first symbol is a '{' as the spec says.
|
||||
// (there are probably some corner cases like leading whitespace)
|
||||
#[serde(with = "ruma_serde::json_string")]
|
||||
/// A complete filter definition serialized to JSON.
|
||||
#[serde(with = "ruma_serde::json_string")]
|
||||
FilterDefinition(FilterDefinition<'a>),
|
||||
|
||||
/// The ID of a filter saved on the server.
|
||||
|
@ -53,6 +53,7 @@ impl Response {
|
||||
/// A mark for whether the user is typing within a length of time or not.
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(into = "TypingInner")]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum Typing {
|
||||
/// Not typing.
|
||||
No,
|
||||
|
@ -116,6 +116,7 @@ impl AuthFlow {
|
||||
|
||||
/// Contains either a User-Interactive Authentication API response body or a Matrix error.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum UiaaResponse {
|
||||
/// User-Interactive Authentication API response
|
||||
AuthResponse(UiaaInfo),
|
||||
|
Loading…
x
Reference in New Issue
Block a user