From a3ae7416997eb1be9d8bb834e1e50209196aa300 Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Thu, 3 Sep 2020 14:55:11 -0400 Subject: [PATCH] Add unstable-exhaustive-types flag to ruma-common --- ruma-common/Cargo.toml | 3 +++ ruma-common/src/directory.rs | 6 +++--- ruma-common/src/encryption.rs | 4 ++-- ruma-common/src/presence.rs | 2 +- ruma-common/src/push.rs | 8 ++++---- ruma-common/src/push/action.rs | 4 ++-- ruma-common/src/push/any_push_rule.rs | 6 +++--- ruma-common/src/push/condition.rs | 2 +- ruma-common/src/thirdparty.rs | 10 +++++----- ruma/Cargo.toml | 1 + 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ruma-common/Cargo.toml b/ruma-common/Cargo.toml index e5eeb085..977dd839 100644 --- a/ruma-common/Cargo.toml +++ b/ruma-common/Cargo.toml @@ -21,3 +21,6 @@ strum = { version = "0.19.2", features = ["derive"] } [dev-dependencies] matches = "0.1.8" + +[features] +unstable-exhaustive-types = [] diff --git a/ruma-common/src/directory.rs b/ruma-common/src/directory.rs index ed4b209f..64e7a768 100644 --- a/ruma-common/src/directory.rs +++ b/ruma-common/src/directory.rs @@ -18,7 +18,7 @@ use serde_json::Value as JsonValue; /// To create an instance of this type, first create a `PublicRoomsChunkInit` and convert it via /// `PublicRoomsChunk::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PublicRoomsChunk { /// Aliases of the room. #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -97,7 +97,7 @@ impl From for PublicRoomsChunk { /// A filter for public rooms lists #[derive(Clone, Debug, Default, Outgoing, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Filter<'a> { /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. #[serde(skip_serializing_if = "Option::is_none")] @@ -114,7 +114,7 @@ impl Filter<'_> { /// Information about which networks/protocols from application services on the /// homeserver from which to request rooms. #[derive(Clone, Debug, PartialEq, Eq, Outgoing)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, PartialEq, Eq, !Deserialize)] pub enum RoomNetwork<'a> { /// Return rooms from the Matrix network. diff --git a/ruma-common/src/encryption.rs b/ruma-common/src/encryption.rs index 7b13cca8..44572b94 100644 --- a/ruma-common/src/encryption.rs +++ b/ruma-common/src/encryption.rs @@ -11,7 +11,7 @@ use serde::Serialize; /// Identity keys for a device. #[derive(Clone, Debug, Outgoing, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Serialize)] pub struct DeviceKeys<'a> { /// The ID of the user the device belongs to. Must match the user ID used when logging in. @@ -51,7 +51,7 @@ impl<'a> DeviceKeys<'a> { /// Additional data added to device key information by intermediate servers. #[derive(Clone, Debug, Default, Outgoing, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Serialize)] pub struct UnsignedDeviceInfo<'a> { /// The display name which the user set on the device. diff --git a/ruma-common/src/presence.rs b/ruma-common/src/presence.rs index f5b7d855..9953a576 100644 --- a/ruma-common/src/presence.rs +++ b/ruma-common/src/presence.rs @@ -7,7 +7,7 @@ use strum::{Display, EnumString}; /// A description of a user's connectivity and availability for chat. #[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum PresenceState { diff --git a/ruma-common/src/push.rs b/ruma-common/src/push.rs index 033650e3..5687cc3d 100644 --- a/ruma-common/src/push.rs +++ b/ruma-common/src/push.rs @@ -19,7 +19,7 @@ pub use self::{ /// For example, some rules may only be applied for messages from a particular sender, a particular /// room, or by default. The push ruleset contains the entire set of scopes and rules. #[derive(Clone, Debug, Default, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Ruleset { /// These rules configure behavior for (unencrypted) messages that match certain patterns. pub content: Vec, @@ -58,7 +58,7 @@ impl Ruleset { /// To create an instance of this type, first create a `PushRuleInit` and convert it via /// `PushRule::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PushRule { /// Actions to determine if and how a notification is delivered for events matching this rule. pub actions: Vec, @@ -106,7 +106,7 @@ impl From for PushRule { /// To create an instance of this type, first create a `ConditionalPushRuleInit` and convert it via /// `ConditionalPushRule::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct ConditionalPushRule { /// Actions to determine if and how a notification is delivered for events matching this rule. pub actions: Vec, @@ -166,7 +166,7 @@ impl From for ConditionalPushRule { /// To create an instance of this type, first create a `PatternedPushRuleInit` and convert it via /// `PatternedPushRule::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct PatternedPushRule { /// Actions to determine if and how a notification is delivered for events matching this rule. pub actions: Vec, diff --git a/ruma-common/src/push/action.rs b/ruma-common/src/push/action.rs index 39407a5f..62a03b94 100644 --- a/ruma-common/src/push/action.rs +++ b/ruma-common/src/push/action.rs @@ -8,7 +8,7 @@ use serde_json::value::RawValue as RawJsonValue; /// /// See https://matrix.org/docs/spec/client_server/r0.6.0#actions for details. #[derive(Clone, Debug)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub enum Action { /// Causes matching events to generate a notification. Notify, @@ -26,7 +26,7 @@ pub enum Action { /// The `set_tweak` action. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(from = "tweak_serde::Tweak", into = "tweak_serde::Tweak")] pub enum Tweak { /// A string representing the sound to be played when this notification arrives. diff --git a/ruma-common/src/push/any_push_rule.rs b/ruma-common/src/push/any_push_rule.rs index 9d8ff6a2..2e10e3b1 100644 --- a/ruma-common/src/push/any_push_rule.rs +++ b/ruma-common/src/push/any_push_rule.rs @@ -16,7 +16,7 @@ use super::{ /// /// To create an instance of this type, use one of its `From` implementations. #[derive(Clone, Debug, Serialize, Deserialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct AnyPushRule { /// The actions to perform when this rule is matched. pub actions: Vec, @@ -94,7 +94,7 @@ impl From for PushRule { /// An error that happens when `AnyPushRule` cannot /// be converted into `PatternedPushRule` #[derive(Debug)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct MissingPatternError; impl Display for MissingPatternError { @@ -122,7 +122,7 @@ impl TryFrom for PatternedPushRule { /// An error that happens when `AnyPushRule` cannot /// be converted into `ConditionalPushRule` #[derive(Debug)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct MissingConditionsError; impl Display for MissingConditionsError { diff --git a/ruma-common/src/push/condition.rs b/ruma-common/src/push/condition.rs index e971b6de..5ef24559 100644 --- a/ruma-common/src/push/condition.rs +++ b/ruma-common/src/push/condition.rs @@ -6,7 +6,7 @@ pub use room_member_count_is::{ComparisonOperator, RoomMemberCountIs}; /// A condition that must apply for an associated push rule's action to be taken. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "kind", rename_all = "snake_case")] pub enum PushCondition { /// This is a glob pattern match on a field of the event. diff --git a/ruma-common/src/thirdparty.rs b/ruma-common/src/thirdparty.rs index 70c561fa..783a66e4 100644 --- a/ruma-common/src/thirdparty.rs +++ b/ruma-common/src/thirdparty.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; /// To create an instance of this type, first create a `ProtocolInit` and convert it via /// `Protocol::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Protocol { /// Fields which may be used to identify a third party user. pub user_fields: Vec, @@ -65,7 +65,7 @@ impl From for Protocol { /// To create an instance of this type, first create a `ProtocolInstanceInit` and convert it via /// `ProtocolInstance::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct ProtocolInstance { /// A human-readable description for the protocol, such as the name. pub desc: String, @@ -109,7 +109,7 @@ impl From for ProtocolInstance { /// To create an instance of this type, first create a `FieldTypeInit` and convert it via /// `FieldType::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct FieldType { /// A regular expression for validation of a field's value. pub regexp: String, @@ -140,7 +140,7 @@ impl From for FieldType { /// A third party network location. #[derive(Clone, Debug, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Location { /// An alias for a matrix room. pub alias: RoomAliasId, @@ -181,7 +181,7 @@ impl User { /// The medium of a third party identifier. #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] -#[non_exhaustive] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(rename_all = "lowercase")] pub enum Medium { /// Email address identifier diff --git a/ruma/Cargo.toml b/ruma/Cargo.toml index 8adb6b33..0fcc5688 100644 --- a/ruma/Cargo.toml +++ b/ruma/Cargo.toml @@ -20,6 +20,7 @@ unstable-exhaustive-types = [ "ruma-appservice-api/unstable-exhaustive-types", "ruma-client-api/unstable-exhaustive-types", "ruma-federation-api/unstable-exhaustive-types", + "ruma-common/unstable-exhaustive-types", ] unstable-pre-spec = ["ruma-client-api/unstable-pre-spec"] unstable-synapse-quirks = ["ruma-client-api/unstable-synapse-quirks"]