Use Default derive for enums
This commit is contained in:
parent
66ff4dbaad
commit
4fb051ba0f
@ -169,7 +169,7 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
/// The kind of account being registered.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum RegistrationKind {
|
||||
@ -179,15 +179,10 @@ pub enum RegistrationKind {
|
||||
Guest,
|
||||
|
||||
/// A regular user account
|
||||
#[default]
|
||||
User,
|
||||
}
|
||||
|
||||
impl Default for RegistrationKind {
|
||||
fn default() -> Self {
|
||||
Self::User
|
||||
}
|
||||
}
|
||||
|
||||
/// The login type.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -21,11 +21,12 @@ pub use self::{lazy_load::LazyLoadOptions, url::UrlFilter};
|
||||
|
||||
/// Format to use for returned events.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum EventFormat {
|
||||
/// Client format, as described in the Client API.
|
||||
#[default]
|
||||
Client,
|
||||
|
||||
/// Raw events from federation.
|
||||
@ -35,12 +36,6 @@ pub enum EventFormat {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for EventFormat {
|
||||
fn default() -> Self {
|
||||
Self::Client
|
||||
}
|
||||
}
|
||||
|
||||
/// Filters to be applied to room events.
|
||||
#[derive(Clone, Debug, Default, Incoming, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -4,11 +4,12 @@ use serde::{ser::SerializeStruct as _, Deserialize, Serialize, Serializer};
|
||||
/// supported endpoints
|
||||
///
|
||||
/// [lazy-loading]: https://spec.matrix.org/v1.2/client-server-api/#lazy-loading-room-members
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Deserialize)]
|
||||
#[serde(from = "LazyLoadJsonRepr")]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum LazyLoadOptions {
|
||||
/// Disables lazy-loading of membership events.
|
||||
#[default]
|
||||
Disabled,
|
||||
|
||||
/// Enables lazy-loading of events.
|
||||
@ -28,13 +29,6 @@ impl LazyLoadOptions {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LazyLoadOptions {
|
||||
/// `LazyLoadOptions::Disabled`
|
||||
fn default() -> Self {
|
||||
Self::Disabled
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for LazyLoadOptions {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -12,7 +12,7 @@ use crate::PrivOwnedStr;
|
||||
|
||||
/// Whether or not a newly created room will be listed in the room directory.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum Visibility {
|
||||
@ -20,14 +20,9 @@ pub enum Visibility {
|
||||
Public,
|
||||
|
||||
/// Indicates that the room will not be shown in the published room list.
|
||||
#[default]
|
||||
Private,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for Visibility {
|
||||
fn default() -> Self {
|
||||
Self::Private
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl From<SpaceHierarchyRoomsChunkInit> for SpaceHierarchyRoomsChunk {
|
||||
/// enum does not hold the conditions for joining restricted rooms. Instead, the server is assumed
|
||||
/// to only return rooms the user is allowed to join in a space hierarchy listing response.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum SpaceRoomJoinRule {
|
||||
@ -171,14 +171,9 @@ pub enum SpaceRoomJoinRule {
|
||||
KnockRestricted,
|
||||
|
||||
/// Anyone can join the room without any prior action.
|
||||
#[default]
|
||||
Public,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for SpaceRoomJoinRule {
|
||||
fn default() -> Self {
|
||||
SpaceRoomJoinRule::Public
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub type CanonicalJsonObject = BTreeMap<String, CanonicalJsonValue>;
|
||||
|
||||
/// Represents a canonical JSON value as per the Matrix specification.
|
||||
#[cfg(feature = "canonical-json")]
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
#[derive(Clone, Default, Eq, PartialEq)]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum CanonicalJsonValue {
|
||||
/// Represents a JSON null value.
|
||||
@ -22,6 +22,7 @@ pub enum CanonicalJsonValue {
|
||||
/// # use ruma_common::CanonicalJsonValue;
|
||||
/// let v: CanonicalJsonValue = json!(null).try_into().unwrap();
|
||||
/// ```
|
||||
#[default]
|
||||
Null,
|
||||
|
||||
/// Represents a JSON boolean.
|
||||
@ -155,12 +156,6 @@ impl CanonicalJsonValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CanonicalJsonValue {
|
||||
fn default() -> Self {
|
||||
Self::Null
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for CanonicalJsonValue {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
|
@ -185,7 +185,7 @@ impl<'a> Default for RoomNetwork<'a> {
|
||||
|
||||
/// The rule used for users wishing to join a public room.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum PublicRoomJoinRule {
|
||||
@ -193,18 +193,13 @@ pub enum PublicRoomJoinRule {
|
||||
Knock,
|
||||
|
||||
/// Anyone can join the room without any prior action.
|
||||
#[default]
|
||||
Public,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for PublicRoomJoinRule {
|
||||
fn default() -> Self {
|
||||
Self::Public
|
||||
}
|
||||
}
|
||||
|
||||
/// An enum of possible room types to filter.
|
||||
///
|
||||
/// This type can hold an arbitrary string. To build this with a custom value, convert it from an
|
||||
|
@ -86,6 +86,7 @@ impl CallHangupEventContent {
|
||||
/// `invite_timeout` for when the other party did not answer in time.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[cfg_attr(feature = "unstable-msc2746", derive(Default))]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum Reason {
|
||||
@ -105,6 +106,7 @@ pub enum Reason {
|
||||
|
||||
/// The user chose to end the call.
|
||||
#[cfg(feature = "unstable-msc2746")]
|
||||
#[default]
|
||||
UserHangup,
|
||||
|
||||
/// The client was unable to start capturing media in such a way as it is unable to continue
|
||||
@ -146,10 +148,3 @@ impl Reason {
|
||||
Some(Self::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-msc2746")]
|
||||
impl Default for Reason {
|
||||
fn default() -> Self {
|
||||
Self::UserHangup
|
||||
}
|
||||
}
|
||||
|
@ -191,19 +191,14 @@ impl AssetContent {
|
||||
|
||||
/// The type of an asset.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
|
||||
#[non_exhaustive]
|
||||
pub enum AssetType {
|
||||
/// The asset is the sender of the event.
|
||||
#[default]
|
||||
#[ruma_enum(rename = "m.self")]
|
||||
Self_,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for AssetType {
|
||||
fn default() -> Self {
|
||||
Self::Self_
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,11 @@ impl PollStartContent {
|
||||
|
||||
/// The kind of poll.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub enum PollKind {
|
||||
/// The results are revealed once the poll is closed.
|
||||
#[default]
|
||||
#[ruma_enum(rename = "org.matrix.msc3381.poll.undisclosed", alias = "m.poll.undisclosed")]
|
||||
Undisclosed,
|
||||
|
||||
@ -89,12 +90,6 @@ pub enum PollKind {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for PollKind {
|
||||
fn default() -> Self {
|
||||
Self::Undisclosed
|
||||
}
|
||||
}
|
||||
|
||||
/// The answers to a poll.
|
||||
///
|
||||
/// Must include between 1 and 20 `PollAnswer`s.
|
||||
|
@ -6,7 +6,7 @@ use crate::{serde::StringEnum, PrivOwnedStr};
|
||||
|
||||
/// A description of a user's connectivity and availability for chat.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum PresenceState {
|
||||
@ -14,6 +14,7 @@ pub enum PresenceState {
|
||||
Offline,
|
||||
|
||||
/// Connected to the service.
|
||||
#[default]
|
||||
Online,
|
||||
|
||||
/// Connected to the service but not available for chat.
|
||||
@ -23,12 +24,6 @@ pub enum PresenceState {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for PresenceState {
|
||||
fn default() -> Self {
|
||||
Self::Online
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for &'_ PresenceState {
|
||||
fn default() -> Self {
|
||||
&PresenceState::Online
|
||||
|
@ -10,10 +10,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
/// One of `==`, `<`, `>`, `>=` or `<=`.
|
||||
///
|
||||
/// Used by `RoomMemberCountIs`. Defaults to `==`.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
|
||||
#[allow(clippy::exhaustive_enums)]
|
||||
pub enum ComparisonOperator {
|
||||
/// Equals
|
||||
#[default]
|
||||
Eq,
|
||||
|
||||
/// Less than
|
||||
@ -29,12 +30,6 @@ pub enum ComparisonOperator {
|
||||
Le,
|
||||
}
|
||||
|
||||
impl Default for ComparisonOperator {
|
||||
fn default() -> Self {
|
||||
ComparisonOperator::Eq
|
||||
}
|
||||
}
|
||||
|
||||
/// A decimal integer optionally prefixed by one of `==`, `<`, `>`, `>=` or `<=`.
|
||||
///
|
||||
/// A prefix of `<` matches rooms where the member count is strictly less than the given
|
||||
|
@ -148,11 +148,12 @@ pub mod v1 {
|
||||
/// This type can hold an arbitrary string. To build this with a custom value, convert it from a
|
||||
/// string with `::from() / .into()`. To check for values 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, Default, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum NotificationPriority {
|
||||
/// A high priority notification
|
||||
#[default]
|
||||
High,
|
||||
|
||||
/// A low priority notification
|
||||
@ -162,12 +163,6 @@ pub mod v1 {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Default for NotificationPriority {
|
||||
fn default() -> Self {
|
||||
Self::High
|
||||
}
|
||||
}
|
||||
|
||||
/// Type for passing information about notification counts.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user