diff --git a/crates/ruma-client-api/src/account/register.rs b/crates/ruma-client-api/src/account/register.rs index fca2a2b1..93239cee 100644 --- a/crates/ruma-client-api/src/account/register.rs +++ b/crates/ruma-client-api/src/account/register.rs @@ -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)] diff --git a/crates/ruma-client-api/src/filter.rs b/crates/ruma-client-api/src/filter.rs index 56005b27..1e2a2f67 100644 --- a/crates/ruma-client-api/src/filter.rs +++ b/crates/ruma-client-api/src/filter.rs @@ -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)] diff --git a/crates/ruma-client-api/src/filter/lazy_load.rs b/crates/ruma-client-api/src/filter/lazy_load.rs index adfdb49d..bd6e3891 100644 --- a/crates/ruma-client-api/src/filter/lazy_load.rs +++ b/crates/ruma-client-api/src/filter/lazy_load.rs @@ -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(&self, serializer: S) -> Result where diff --git a/crates/ruma-client-api/src/room.rs b/crates/ruma-client-api/src/room.rs index 352156ec..34da3216 100644 --- a/crates/ruma-client-api/src/room.rs +++ b/crates/ruma-client-api/src/room.rs @@ -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 - } -} diff --git a/crates/ruma-client-api/src/space.rs b/crates/ruma-client-api/src/space.rs index c147e57b..57c00c33 100644 --- a/crates/ruma-client-api/src/space.rs +++ b/crates/ruma-client-api/src/space.rs @@ -142,7 +142,7 @@ impl From 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 - } -} diff --git a/crates/ruma-common/src/canonical_json/value.rs b/crates/ruma-common/src/canonical_json/value.rs index 90812fac..875026c5 100644 --- a/crates/ruma-common/src/canonical_json/value.rs +++ b/crates/ruma-common/src/canonical_json/value.rs @@ -12,7 +12,7 @@ pub type CanonicalJsonObject = BTreeMap; /// 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 { diff --git a/crates/ruma-common/src/directory.rs b/crates/ruma-common/src/directory.rs index f9e34f98..4ab91f8c 100644 --- a/crates/ruma-common/src/directory.rs +++ b/crates/ruma-common/src/directory.rs @@ -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 diff --git a/crates/ruma-common/src/events/call/hangup.rs b/crates/ruma-common/src/events/call/hangup.rs index 478e1f84..da970489 100644 --- a/crates/ruma-common/src/events/call/hangup.rs +++ b/crates/ruma-common/src/events/call/hangup.rs @@ -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 - } -} diff --git a/crates/ruma-common/src/events/location.rs b/crates/ruma-common/src/events/location.rs index 783caa6d..5851ef8a 100644 --- a/crates/ruma-common/src/events/location.rs +++ b/crates/ruma-common/src/events/location.rs @@ -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_ - } -} diff --git a/crates/ruma-common/src/events/poll/start.rs b/crates/ruma-common/src/events/poll/start.rs index 03c154fd..d2b7e585 100644 --- a/crates/ruma-common/src/events/poll/start.rs +++ b/crates/ruma-common/src/events/poll/start.rs @@ -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. diff --git a/crates/ruma-common/src/presence.rs b/crates/ruma-common/src/presence.rs index db1739f6..9bb0e84a 100644 --- a/crates/ruma-common/src/presence.rs +++ b/crates/ruma-common/src/presence.rs @@ -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 diff --git a/crates/ruma-common/src/push/condition/room_member_count_is.rs b/crates/ruma-common/src/push/condition/room_member_count_is.rs index f97b68cf..3ac737a6 100644 --- a/crates/ruma-common/src/push/condition/room_member_count_is.rs +++ b/crates/ruma-common/src/push/condition/room_member_count_is.rs @@ -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 diff --git a/crates/ruma-push-gateway-api/src/send_event_notification.rs b/crates/ruma-push-gateway-api/src/send_event_notification.rs index 1a1e463b..e56d849b 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification.rs @@ -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)]