From 891db9083ba520608255f5febc2183af4df5fa5f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 2 Feb 2021 19:12:46 +0100 Subject: [PATCH] Clean up cargo features --- ruma-appservice-api/Cargo.toml | 1 - ruma-client-api/Cargo.toml | 6 +-- ruma-client/Cargo.toml | 2 - ruma-common/Cargo.toml | 2 +- ruma-common/src/thirdparty.rs | 6 +-- ruma-events/Cargo.toml | 7 ++-- ruma-events/src/room/power_levels.rs | 44 +++++----------------- ruma-events/src/room/third_party_invite.rs | 6 +-- ruma-events/src/room/tombstone.rs | 2 +- ruma-federation-api/Cargo.toml | 3 +- ruma-push-gateway-api/Cargo.toml | 1 - ruma/Cargo.toml | 31 +++++++++------ 12 files changed, 44 insertions(+), 67 deletions(-) diff --git a/ruma-appservice-api/Cargo.toml b/ruma-appservice-api/Cargo.toml index 15646399..08b730b7 100644 --- a/ruma-appservice-api/Cargo.toml +++ b/ruma-appservice-api/Cargo.toml @@ -22,4 +22,3 @@ serde_json = "1.0.61" [features] unstable-exhaustive-types = [] -unstable-synapse-quirks = ["ruma-events/unstable-synapse-quirks"] diff --git a/ruma-client-api/Cargo.toml b/ruma-client-api/Cargo.toml index 555bb772..47256d4c 100644 --- a/ruma-client-api/Cargo.toml +++ b/ruma-client-api/Cargo.toml @@ -35,8 +35,4 @@ matches = "0.1.8" [features] unstable-exhaustive-types = [] -unstable-pre-spec = ["ruma-common/unstable-pre-spec"] -unstable-synapse-quirks = [ - "ruma-common/unstable-synapse-quirks", - "ruma-events/unstable-synapse-quirks", -] +unstable-pre-spec = [] diff --git a/ruma-client/Cargo.toml b/ruma-client/Cargo.toml index 1d78db3a..c6c843aa 100644 --- a/ruma-client/Cargo.toml +++ b/ruma-client/Cargo.toml @@ -54,8 +54,6 @@ tls-rustls-webpki-roots = [ "_tls-rustls", ] -unstable-synapse-quirks = ["ruma-events/unstable-synapse-quirks"] - # Internal, not meant to be used directly _tls = [] _tls-rustls = ["_tls"] diff --git a/ruma-common/Cargo.toml b/ruma-common/Cargo.toml index 14f359d1..b87c7aa9 100644 --- a/ruma-common/Cargo.toml +++ b/ruma-common/Cargo.toml @@ -22,6 +22,6 @@ serde_json = { version = "1.0.60", features = ["raw_value"] } matches = "0.1.8" [features] +compat = [] unstable-exhaustive-types = [] -unstable-synapse-quirks = [] unstable-pre-spec = [] diff --git a/ruma-common/src/thirdparty.rs b/ruma-common/src/thirdparty.rs index f95d42a0..7e30d5e5 100644 --- a/ruma-common/src/thirdparty.rs +++ b/ruma-common/src/thirdparty.rs @@ -24,9 +24,9 @@ pub struct Protocol { /// A content URI representing an icon for the third party protocol. /// - /// If you activate the `unstable-synapse-quirks` feature, this field being absent in JSON will - /// give you an empty string here. - #[cfg_attr(feature = "unstable-synapse-quirks", serde(default))] + /// If you activate the `compat` feature, this field being absent in JSON will give you an + /// empty string here. + #[cfg_attr(feature = "compat", serde(default))] pub icon: String, /// The type definitions for the fields defined in `user_fields` and `location_fields`. diff --git a/ruma-events/Cargo.toml b/ruma-events/Cargo.toml index b46f674e..a31a8a8d 100644 --- a/ruma-events/Cargo.toml +++ b/ruma-events/Cargo.toml @@ -29,11 +29,12 @@ ruma-identifiers = { version = "=0.18.0-alpha.1", path = "../ruma-identifiers", trybuild = "1.0.38" [features] -unstable-exhaustive-types = [] -unstable-pre-spec = ["ruma-common/unstable-pre-spec"] -unstable-synapse-quirks = [] +compat = [] markdown = ["pulldown-cmark"] +unstable-exhaustive-types = [] +unstable-pre-spec = [] + [[bench]] name = "event_deserialize" harness = false diff --git a/ruma-events/src/room/power_levels.rs b/ruma-events/src/room/power_levels.rs index 22a3ce2e..593ff01c 100644 --- a/ruma-events/src/room/power_levels.rs +++ b/ruma-events/src/room/power_levels.rs @@ -17,10 +17,7 @@ pub type PowerLevelsEvent = StateEvent; #[ruma_event(type = "m.room.power_levels")] pub struct PowerLevelsEventContent { /// The level required to ban a user. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")] #[ruma_event(skip_redaction)] pub ban: Int, @@ -29,7 +26,7 @@ pub struct PowerLevelsEventContent { /// /// This is a mapping from event type to power level required. #[cfg_attr( - feature = "unstable-synapse-quirks", + feature = "compat", serde(deserialize_with = "ruma_serde::btreemap_int_or_string_to_int_values") )] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -37,45 +34,30 @@ pub struct PowerLevelsEventContent { pub events: BTreeMap, /// The default level required to send message events. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_event(skip_redaction)] pub events_default: Int, /// The level required to invite a user. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")] pub invite: Int, /// The level required to kick a user. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")] #[ruma_event(skip_redaction)] pub kick: Int, /// The level required to redact an event. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")] #[ruma_event(skip_redaction)] pub redact: Int, /// The default level required to send state events. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level", skip_serializing_if = "is_default_power_level")] #[ruma_event(skip_redaction)] pub state_default: Int, @@ -84,7 +66,7 @@ pub struct PowerLevelsEventContent { /// /// This is a mapping from `user_id` to power level for that user. #[cfg_attr( - feature = "unstable-synapse-quirks", + feature = "compat", serde(deserialize_with = "ruma_serde::btreemap_int_or_string_to_int_values") )] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] @@ -92,10 +74,7 @@ pub struct PowerLevelsEventContent { pub users: BTreeMap, /// The default power level for every user in the room. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[ruma_event(skip_redaction)] pub users_default: Int, @@ -130,10 +109,7 @@ impl Default for PowerLevelsEventContent { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct NotificationPowerLevels { /// The level required to trigger an `@room` notification. - #[cfg_attr( - feature = "unstable-synapse-quirks", - serde(deserialize_with = "ruma_serde::int_or_string_to_int") - )] + #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[serde(default = "default_power_level")] pub room: Int, } diff --git a/ruma-events/src/room/third_party_invite.rs b/ruma-events/src/room/third_party_invite.rs index fd9b4943..eb226ca3 100644 --- a/ruma-events/src/room/third_party_invite.rs +++ b/ruma-events/src/room/third_party_invite.rs @@ -17,15 +17,15 @@ pub type ThirdPartyInviteEvent = StateEvent; #[ruma_event(type = "m.room.third_party_invite")] pub struct ThirdPartyInviteEventContent { /// A user-readable string which represents the user who has been invited. - #[cfg_attr(feature = "unstable-synapse-quirks", serde(default))] + #[cfg_attr(feature = "compat", serde(default))] pub display_name: String, /// A URL which can be fetched to validate whether the key has been revoked. - #[cfg_attr(feature = "unstable-synapse-quirks", serde(default))] + #[cfg_attr(feature = "compat", serde(default))] pub key_validity_url: String, /// A Base64-encoded Ed25519 key with which the token must be signed. - #[cfg_attr(feature = "unstable-synapse-quirks", serde(default))] + #[cfg_attr(feature = "compat", serde(default))] pub public_key: String, /// Keys with which the token may be signed. diff --git a/ruma-events/src/room/tombstone.rs b/ruma-events/src/room/tombstone.rs index d4f6eb98..0496a640 100644 --- a/ruma-events/src/room/tombstone.rs +++ b/ruma-events/src/room/tombstone.rs @@ -15,7 +15,7 @@ pub type TombstoneEvent = StateEvent; #[ruma_event(type = "m.room.tombstone")] pub struct TombstoneEventContent { /// A server-defined message. - #[cfg_attr(feature = "unstable-synapse-quirks", serde(default))] + #[cfg_attr(feature = "compat", serde(default))] pub body: String, /// The new room the client should be visiting. diff --git a/ruma-federation-api/Cargo.toml b/ruma-federation-api/Cargo.toml index ce7c557a..5f033aee 100644 --- a/ruma-federation-api/Cargo.toml +++ b/ruma-federation-api/Cargo.toml @@ -29,5 +29,4 @@ matches = "0.1.8" [features] unstable-exhaustive-types = [] -unstable-pre-spec = ["ruma-common/unstable-pre-spec"] -unstable-synapse-quirks = ["ruma-events/unstable-synapse-quirks"] +unstable-pre-spec = [] diff --git a/ruma-push-gateway-api/Cargo.toml b/ruma-push-gateway-api/Cargo.toml index d7250e7a..a39a35e8 100644 --- a/ruma-push-gateway-api/Cargo.toml +++ b/ruma-push-gateway-api/Cargo.toml @@ -22,4 +22,3 @@ serde_json = "1.0.61" [features] unstable-exhaustive-types = [] -unstable-synapse-quirks = ["ruma-events/unstable-synapse-quirks"] diff --git a/ruma/Cargo.toml b/ruma/Cargo.toml index de65a781..aa6c33a3 100644 --- a/ruma/Cargo.toml +++ b/ruma/Cargo.toml @@ -33,9 +33,6 @@ ruma-push-gateway-api = { version = "0.0.1", path = "../ruma-push-gateway-api", serde = { version = "1.0.118", features = ["derive"] } [features] -either = ["ruma-identifiers/either"] -rand = ["ruma-identifiers/rand"] - api = ["ruma-api"] events = ["ruma-events"] signatures = ["ruma-signatures"] @@ -46,22 +43,34 @@ federation-api = ["api", "signatures", "ruma-federation-api"] identity-service-api = ["api", "ruma-identity-service-api"] push-gateway-api = ["api", "ruma-push-gateway-api"] +# Concenience features +either = ["ruma-identifiers/either"] +rand = ["ruma-identifiers/rand"] +markdown = ["ruma-events/markdown"] + +# Increase compatibility with other parts of the Matrix ecosystem, at the +# expense of weird behaviour where things deviate from the specification. +# +# For example, some mandatory string fields are defaulted to an empty string if +# missing with this feature. +compat = ["ruma-common/compat", "ruma-events/compat"] + +# unstable: by using any of these, you opt out of all semver guarantees Ruma +# otherwise provides! unstable-exhaustive-types = [ + "ruma-common/unstable-exhaustive-types", "ruma-events/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", + "ruma-identity-service-api/unstable-exhaustive-types", + "ruma-push-gateway-api/unstable-exhaustive-types", ] unstable-pre-spec = [ + "ruma-common/unstable-pre-spec", "ruma-client-api/unstable-pre-spec", "ruma-events/unstable-pre-spec", "ruma-federation-api/unstable-pre-spec", - "ruma-common/unstable-pre-spec", + #"ruma-identity-service-api/unstable-pre-spec", + #"ruma-push-gateway-api/unstable-pre-spec", ] -unstable-synapse-quirks = [ - "ruma-client-api/unstable-synapse-quirks", - "ruma-common/unstable-synapse-quirks", - "ruma-events/unstable-synapse-quirks", -] -markdown = ["ruma-events/markdown"]