From a6a530dcc8331f05fe7a34a1483ecd303f14e29a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 21 Mar 2022 15:49:00 +0100 Subject: [PATCH] serde: Rename derive macro Outgoing to Incoming All it does now is generate `Incoming{Self}` types. --- crates/ruma-client-api/src/account.rs | 4 +- crates/ruma-client-api/src/filter.rs | 10 ++-- crates/ruma-client-api/src/membership.rs | 6 +-- .../src/membership/invite_user.rs | 4 +- .../src/search/search_events.rs | 8 +-- crates/ruma-client-api/src/session/login.rs | 10 ++-- .../src/state/get_state_events_for_key.rs | 4 +- .../src/state/send_state_event.rs | 4 +- .../ruma-client-api/src/sync/sync_events.rs | 4 +- crates/ruma-client-api/src/uiaa.rs | 20 +++---- crates/ruma-client-api/src/uiaa/user_serde.rs | 4 +- crates/ruma-common/src/directory.rs | 6 +-- crates/ruma-common/src/serde.rs | 2 +- .../tests/api/ruma_api_lifetime.rs | 2 +- .../tests/api/ui/05-request-only.rs | 4 +- crates/ruma-macros/src/api/api_request.rs | 2 +- crates/ruma-macros/src/api/api_response.rs | 2 +- crates/ruma-macros/src/api/request.rs | 4 +- crates/ruma-macros/src/api/response.rs | 2 +- crates/ruma-macros/src/lib.rs | 54 +++---------------- crates/ruma-macros/src/serde.rs | 2 +- .../src/serde/{outgoing.rs => incoming.rs} | 4 +- .../src/send_event_notification.rs | 6 +-- crates/ruma/src/lib.rs | 2 +- crates/ruma/tests/outgoing.rs | 8 +-- 25 files changed, 68 insertions(+), 110 deletions(-) rename crates/ruma-macros/src/serde/{outgoing.rs => incoming.rs} (98%) diff --git a/crates/ruma-client-api/src/account.rs b/crates/ruma-client-api/src/account.rs index 03c3532d..e7ee5eae 100644 --- a/crates/ruma-client-api/src/account.rs +++ b/crates/ruma-client-api/src/account.rs @@ -19,13 +19,13 @@ pub mod request_registration_token_via_msisdn; pub mod unbind_3pid; pub mod whoami; -use ruma_common::serde::{Outgoing, StringEnum}; +use ruma_common::serde::{Incoming, StringEnum}; use serde::Serialize; use crate::PrivOwnedStr; /// Additional authentication information for requestToken endpoints. -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct IdentityServerInfo<'a> { /// The ID server to send the onward request to as a hostname with an diff --git a/crates/ruma-client-api/src/filter.rs b/crates/ruma-client-api/src/filter.rs index 9a885179..d654990b 100644 --- a/crates/ruma-client-api/src/filter.rs +++ b/crates/ruma-client-api/src/filter.rs @@ -8,7 +8,7 @@ mod url; use js_int::UInt; use ruma_common::{ - serde::{Outgoing, StringEnum}, + serde::{Incoming, StringEnum}, RoomId, UserId, }; use serde::Serialize; @@ -83,7 +83,7 @@ impl RelationType { } /// Filters to be applied to room events. -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Default, Serialize)] pub struct RoomEventFilter<'a> { @@ -228,7 +228,7 @@ impl IncomingRoomEventFilter { } /// Filters to be applied to room data. -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Default, Serialize)] pub struct RoomFilter<'a> { @@ -310,7 +310,7 @@ impl IncomingRoomFilter { } /// Filter for non-room data. -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Default, Serialize)] pub struct Filter<'a> { @@ -382,7 +382,7 @@ impl IncomingFilter { } /// A filter definition -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, Default, Serialize)] pub struct FilterDefinition<'a> { diff --git a/crates/ruma-client-api/src/membership.rs b/crates/ruma-client-api/src/membership.rs index 19e997c3..e0fa2065 100644 --- a/crates/ruma-client-api/src/membership.rs +++ b/crates/ruma-client-api/src/membership.rs @@ -14,12 +14,12 @@ pub mod unban_user; use std::collections::BTreeMap; -use ruma_common::{serde::Outgoing, thirdparty::Medium, ServerName, ServerSigningKeyId, UserId}; +use ruma_common::{serde::Incoming, thirdparty::Medium, ServerName, ServerSigningKeyId, UserId}; use serde::Serialize; /// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// identity which has been invited to the room. -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct ThirdPartySigned<'a> { /// The Matrix ID of the user who issued the invite. @@ -52,7 +52,7 @@ impl<'a> ThirdPartySigned<'a> { /// /// To create an instance of this type, first create a `Invite3pidInit` and convert it via /// `Invite3pid::from` / `.into()`. -#[derive(Clone, Debug, PartialEq, Outgoing, Serialize)] +#[derive(Clone, Debug, PartialEq, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(PartialEq)] pub struct Invite3pid<'a> { diff --git a/crates/ruma-client-api/src/membership/invite_user.rs b/crates/ruma-client-api/src/membership/invite_user.rs index 7c3eacaf..7bb41b75 100644 --- a/crates/ruma-client-api/src/membership/invite_user.rs +++ b/crates/ruma-client-api/src/membership/invite_user.rs @@ -10,7 +10,7 @@ pub mod v3 { //! [spec-mxid]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite //! [spec-3pid]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite-1 - use ruma_common::{api::ruma_api, serde::Outgoing, RoomId, UserId}; + use ruma_common::{api::ruma_api, serde::Incoming, RoomId, UserId}; use serde::Serialize; use crate::membership::{IncomingInvite3pid, Invite3pid}; @@ -62,7 +62,7 @@ pub mod v3 { } /// Distinguishes between invititations by Matrix or third party identifiers. - #[derive(Clone, Debug, PartialEq, Outgoing, Serialize)] + #[derive(Clone, Debug, PartialEq, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(PartialEq)] #[serde(untagged)] diff --git a/crates/ruma-client-api/src/search/search_events.rs b/crates/ruma-client-api/src/search/search_events.rs index 096744ee..3cf670f1 100644 --- a/crates/ruma-client-api/src/search/search_events.rs +++ b/crates/ruma-client-api/src/search/search_events.rs @@ -11,7 +11,7 @@ pub mod v3 { use ruma_common::{ api::ruma_api, events::{AnyRoomEvent, AnyStateEvent}, - serde::{Outgoing, Raw, StringEnum}, + serde::{Incoming, Raw, StringEnum}, EventId, MxcUri, RoomId, UserId, }; use serde::{Deserialize, Serialize}; @@ -67,7 +67,7 @@ pub mod v3 { } /// Categories of events that can be searched for. - #[derive(Clone, Debug, Default, Outgoing, Serialize)] + #[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Categories<'a> { /// Criteria for searching room events. @@ -83,7 +83,7 @@ pub mod v3 { } /// Criteria for searching a category of events. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Criteria<'a> { /// The string to search events for. @@ -275,7 +275,7 @@ pub mod v3 { } /// Requests that the server partitions the result set based on the provided list of keys. - #[derive(Clone, Default, Debug, Outgoing, Serialize)] + #[derive(Clone, Default, Debug, Incoming, Serialize)] #[incoming_derive(Default)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Groupings<'a> { diff --git a/crates/ruma-client-api/src/session/login.rs b/crates/ruma-client-api/src/session/login.rs index 9abdd5fd..7c48f0c9 100644 --- a/crates/ruma-client-api/src/session/login.rs +++ b/crates/ruma-client-api/src/session/login.rs @@ -7,7 +7,7 @@ pub mod v3 { use ruma_common::{ api::ruma_api, - serde::{JsonObject, Outgoing}, + serde::{Incoming, JsonObject}, DeviceId, ServerName, UserId, }; use serde::{ @@ -94,7 +94,7 @@ pub mod v3 { /// /// To construct the custom `LoginInfo` variant you first have to construct /// [`IncomingLoginInfo::new`] and then call [`IncomingLoginInfo::to_outgoing`] on it. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(!Deserialize)] #[serde(untagged)] @@ -177,7 +177,7 @@ pub mod v3 { } /// An identifier and password to supply as authentication. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.password")] pub struct Password<'a> { @@ -203,7 +203,7 @@ pub mod v3 { } /// A token to supply as authentication. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.token")] pub struct Token<'a> { @@ -226,7 +226,7 @@ pub mod v3 { } /// An identifier to supply for Application Service authentication. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.application_service")] pub struct ApplicationService<'a> { diff --git a/crates/ruma-client-api/src/state/get_state_events_for_key.rs b/crates/ruma-client-api/src/state/get_state_events_for_key.rs index ae1d08c4..ca9a8aed 100644 --- a/crates/ruma-client-api/src/state/get_state_events_for_key.rs +++ b/crates/ruma-client-api/src/state/get_state_events_for_key.rs @@ -8,7 +8,7 @@ pub mod v3 { use ruma_common::{ api::ruma_api, events::{AnyStateEventContent, StateEventType}, - serde::{Outgoing, Raw}, + serde::{Incoming, Raw}, RoomId, }; @@ -39,7 +39,7 @@ pub mod v3 { /// Data for a request to the `get_state_events_for_key` API endpoint. /// /// Get state events associated with a given key. - #[derive(Clone, Debug, Outgoing)] + #[derive(Clone, Debug, Incoming)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(!Deserialize)] pub struct Request<'a> { diff --git a/crates/ruma-client-api/src/state/send_state_event.rs b/crates/ruma-client-api/src/state/send_state_event.rs index a7aa2caa..f2f6d4ac 100644 --- a/crates/ruma-client-api/src/state/send_state_event.rs +++ b/crates/ruma-client-api/src/state/send_state_event.rs @@ -8,7 +8,7 @@ pub mod v3 { use ruma_common::{ api::ruma_api, events::{AnyStateEventContent, EventContent, StateEventType}, - serde::{Outgoing, Raw}, + serde::{Incoming, Raw}, EventId, RoomId, }; use serde_json::value::to_raw_value as to_raw_json_value; @@ -36,7 +36,7 @@ pub mod v3 { /// Data for a request to the `send_state_event` API endpoint. /// /// Send a state event to a room associated with a given state key. - #[derive(Clone, Debug, Outgoing)] + #[derive(Clone, Debug, Incoming)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(!Deserialize)] pub struct Request<'a> { diff --git a/crates/ruma-client-api/src/sync/sync_events.rs b/crates/ruma-client-api/src/sync/sync_events.rs index db85a484..e2706e2b 100644 --- a/crates/ruma-client-api/src/sync/sync_events.rs +++ b/crates/ruma-client-api/src/sync/sync_events.rs @@ -16,7 +16,7 @@ pub mod v3 { AnyToDeviceEvent, }, presence::PresenceState, - serde::{Outgoing, Raw}, + serde::{Incoming, Raw}, DeviceKeyAlgorithm, RoomId, UserId, }; use serde::{Deserialize, Serialize}; @@ -138,7 +138,7 @@ pub mod v3 { } /// A filter represented either as its full JSON definition or the ID of a saved filter. - #[derive(Clone, Debug, Outgoing, Serialize)] + #[derive(Clone, Debug, Incoming, Serialize)] #[allow(clippy::large_enum_variant)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(untagged)] diff --git a/crates/ruma-client-api/src/uiaa.rs b/crates/ruma-client-api/src/uiaa.rs index 3cb914c5..15df5170 100644 --- a/crates/ruma-client-api/src/uiaa.rs +++ b/crates/ruma-client-api/src/uiaa.rs @@ -10,7 +10,7 @@ use ruma_common::{ error::{DeserializationError, IntoHttpError}, EndpointError, OutgoingResponse, }, - serde::{from_raw_json_value, JsonObject, Outgoing, StringEnum}, + serde::{from_raw_json_value, Incoming, JsonObject, StringEnum}, thirdparty::Medium, ClientSecret, SessionId, }; @@ -34,7 +34,7 @@ mod user_serde; /// /// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`] /// and then call [`IncomingAuthData::to_outgoing`] on it. -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[non_exhaustive] #[incoming_derive(!Deserialize)] #[serde(untagged)] @@ -342,7 +342,7 @@ pub enum AuthType { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#password-based -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.password")] pub struct Password<'a> { @@ -379,7 +379,7 @@ impl IncomingPassword { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#google-recaptcha -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.recaptcha")] pub struct ReCaptcha<'a> { @@ -409,7 +409,7 @@ impl IncomingReCaptcha { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#email-based-identity--homeserver -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.email.identity")] pub struct EmailIdentity<'a> { @@ -436,7 +436,7 @@ impl IncomingEmailIdentity { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#phone-numbermsisdn-based-identity--homeserver -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.msisdn")] pub struct Msisdn<'a> { @@ -460,7 +460,7 @@ impl IncomingMsisdn { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#dummy-auth -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.dummy")] pub struct Dummy<'a> { @@ -487,7 +487,7 @@ impl IncomingDummy { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#token-authenticated-registration -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "type", rename = "m.login.registration_token")] pub struct RegistrationToken<'a> { @@ -517,7 +517,7 @@ impl IncomingRegistrationToken { /// See [the spec] for how to use this. /// /// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#fallback -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct FallbackAcknowledgement<'a> { /// The value of the session key given by the homeserver. @@ -561,7 +561,7 @@ pub struct IncomingCustomAuthData { } /// Identification information for the user. -#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Incoming, Serialize)] #[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")] #[allow(clippy::exhaustive_enums)] pub enum UserIdentifier<'a> { diff --git a/crates/ruma-client-api/src/uiaa/user_serde.rs b/crates/ruma-client-api/src/uiaa/user_serde.rs index c497bb60..ff80b951 100644 --- a/crates/ruma-client-api/src/uiaa/user_serde.rs +++ b/crates/ruma-client-api/src/uiaa/user_serde.rs @@ -1,12 +1,12 @@ //! Helper module for the Serialize / Deserialize impl's for the User struct //! in the parent module. -use ruma_common::{serde::Outgoing, thirdparty::Medium}; +use ruma_common::{serde::Incoming, thirdparty::Medium}; use serde::Serialize; // The following structs could just be used in place of the one in the parent module, but // that one is arguably much easier to deal with. -#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Incoming, Serialize)] #[serde(tag = "type")] pub(crate) enum UserIdentifier<'a> { #[serde(rename = "m.id.user")] diff --git a/crates/ruma-common/src/directory.rs b/crates/ruma-common/src/directory.rs index c44405d4..ecd0e32e 100644 --- a/crates/ruma-common/src/directory.rs +++ b/crates/ruma-common/src/directory.rs @@ -2,7 +2,7 @@ use std::fmt; -use crate::serde::{Outgoing, StringEnum}; +use crate::serde::{Incoming, StringEnum}; use js_int::UInt; use serde::{ de::{Error, MapAccess, Visitor}, @@ -108,7 +108,7 @@ impl From for PublicRoomsChunk { } /// A filter for public rooms lists -#[derive(Clone, Debug, Default, Outgoing, Serialize)] +#[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Default)] pub struct Filter<'a> { @@ -131,7 +131,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)] +#[derive(Clone, Debug, PartialEq, Eq, Incoming)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[incoming_derive(Clone, PartialEq, Eq, !Deserialize)] pub enum RoomNetwork<'a> { diff --git a/crates/ruma-common/src/serde.rs b/crates/ruma-common/src/serde.rs index 19f13e46..96bb054e 100644 --- a/crates/ruma-common/src/serde.rs +++ b/crates/ruma-common/src/serde.rs @@ -73,6 +73,6 @@ where } pub use ruma_macros::{ - AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, Outgoing, + AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, Incoming, OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde, }; diff --git a/crates/ruma-common/tests/api/ruma_api_lifetime.rs b/crates/ruma-common/tests/api/ruma_api_lifetime.rs index 5bf4c983..ba570382 100644 --- a/crates/ruma-common/tests/api/ruma_api_lifetime.rs +++ b/crates/ruma-common/tests/api/ruma_api_lifetime.rs @@ -1,6 +1,6 @@ #![allow(clippy::exhaustive_structs)] -#[derive(Copy, Clone, Debug, ruma_common::serde::Outgoing, serde::Serialize)] +#[derive(Copy, Clone, Debug, ruma_common::serde::Incoming, serde::Serialize)] pub struct OtherThing<'t> { pub some: &'t str, pub t: &'t [u8], diff --git a/crates/ruma-common/tests/api/ui/05-request-only.rs b/crates/ruma-common/tests/api/ui/05-request-only.rs index 5f449668..12511b10 100644 --- a/crates/ruma-common/tests/api/ui/05-request-only.rs +++ b/crates/ruma-common/tests/api/ui/05-request-only.rs @@ -4,7 +4,7 @@ use ruma_common::{ error::{FromHttpResponseError, IntoHttpError, MatrixError}, ruma_api, IncomingResponse, OutgoingResponse, }, - serde::Outgoing, + serde::Incoming, }; ruma_api! { @@ -25,7 +25,7 @@ ruma_api! { } } -#[derive(Outgoing)] +#[derive(Incoming)] pub struct Response; impl IncomingResponse for Response { diff --git a/crates/ruma-macros/src/api/api_request.rs b/crates/ruma-macros/src/api/api_request.rs index 1be04af4..d3aa957c 100644 --- a/crates/ruma-macros/src/api/api_request.rs +++ b/crates/ruma-macros/src/api/api_request.rs @@ -99,7 +99,7 @@ impl Request { Clone, Debug, #ruma_macros::Request, - #ruma_common::serde::Outgoing, + #ruma_common::serde::Incoming, #ruma_common::serde::_FakeDeriveSerde, )] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] diff --git a/crates/ruma-macros/src/api/api_response.rs b/crates/ruma-macros/src/api/api_response.rs index e03b713f..d881aef7 100644 --- a/crates/ruma-macros/src/api/api_response.rs +++ b/crates/ruma-macros/src/api/api_response.rs @@ -39,7 +39,7 @@ impl Response { Clone, Debug, #ruma_macros::Response, - #ruma_common::serde::Outgoing, + #ruma_common::serde::Incoming, #ruma_common::serde::_FakeDeriveSerde, )] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] diff --git a/crates/ruma-macros/src/api/request.rs b/crates/ruma-macros/src/api/request.rs index b99bd386..98490ebb 100644 --- a/crates/ruma-macros/src/api/request.rs +++ b/crates/ruma-macros/src/api/request.rs @@ -220,7 +220,7 @@ impl Request { #serde::Serialize, #derive_deserialize )] - #[cfg_attr(feature = "server", derive(#ruma_common::serde::Outgoing))] + #[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))] #serde_attr struct RequestBody< #(#lifetimes),* > { #(#fields),* } } @@ -248,7 +248,7 @@ impl Request { #serde::Serialize, #derive_deserialize )] - #[cfg_attr(feature = "server", derive(#ruma_common::serde::Outgoing))] + #[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))] struct RequestQuery< #(#lifetimes),* > #def } }); diff --git a/crates/ruma-macros/src/api/response.rs b/crates/ruma-macros/src/api/response.rs index 12063235..cbccaa0f 100644 --- a/crates/ruma-macros/src/api/response.rs +++ b/crates/ruma-macros/src/api/response.rs @@ -110,7 +110,7 @@ impl Response { #[derive( Debug, #ruma_macros::_FakeDeriveRumaApi, - #ruma_common::serde::Outgoing, + #ruma_common::serde::Incoming, #serde_derives )] #serde_attr diff --git a/crates/ruma-macros/src/lib.rs b/crates/ruma-macros/src/lib.rs index 2fa7a3b1..0d840175 100644 --- a/crates/ruma-macros/src/lib.rs +++ b/crates/ruma-macros/src/lib.rs @@ -37,8 +37,8 @@ use self::{ enum_as_ref_str::expand_enum_as_ref_str, enum_from_string::expand_enum_from_string, eq_as_ref_str::expand_partial_eq_as_ref_str, + incoming::expand_derive_incoming, ord_as_ref_str::{expand_ord_as_ref_str, expand_partial_ord_as_ref_str}, - outgoing::expand_derive_outgoing, serialize_as_ref_str::expand_serialize_as_ref_str, }, util::import_ruma_common, @@ -232,55 +232,13 @@ pub fn user_id(input: TokenStream) -> TokenStream { output.into() } -/// Derive the `Outgoing` trait, possibly generating an 'Incoming' version of the struct this -/// derive macro is used on. +/// Generating an 'Incoming' version of the type this derive macro is used on. /// -/// Specifically, if no lifetime variables are used on any of the fields of the struct, this simple -/// implementation will be generated: -/// -/// ```ignore -/// # // TODO: "ignore" this doctest until it is more extensively documented. (See #541) -/// impl Outgoing for MyType { -/// type Incoming = Self; -/// } -/// ``` -/* - -TODO: Extend docs. Previously: - -If, however, `#[wrap_incoming]` is used (which is the only reason you should ever use this -derive macro manually), a new struct `IncomingT` (where `T` is the type this derive is used on) -is generated, with all of the fields with `#[wrap_incoming]` replaced: - -```ignore -#[derive(Outgoing)] -struct MyType { - pub foo: Foo, - #[wrap_incoming] - pub bar: Bar, - #[wrap_incoming(Baz)] - pub baz: Option, - #[wrap_incoming(with EventResult)] - pub x: XEvent, - #[wrap_incoming(YEvent with EventResult)] - pub ys: Vec, -} - -// generated -struct IncomingMyType { - pub foo: Foo, - pub bar: IncomingBar, - pub baz: Option, - pub x: EventResult, - pub ys: Vec>, -} -``` - -*/ -#[proc_macro_derive(Outgoing, attributes(incoming_derive))] -pub fn derive_outgoing(input: TokenStream) -> TokenStream { +/// This type will be a fully-owned version of the input type, using no lifetime generics. +#[proc_macro_derive(Incoming, attributes(incoming_derive))] +pub fn derive_incoming(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - expand_derive_outgoing(input).unwrap_or_else(syn::Error::into_compile_error).into() + expand_derive_incoming(input).unwrap_or_else(syn::Error::into_compile_error).into() } /// Derive the `AsRef` trait for an enum. diff --git a/crates/ruma-macros/src/serde.rs b/crates/ruma-macros/src/serde.rs index 5cc5c62e..215e789f 100644 --- a/crates/ruma-macros/src/serde.rs +++ b/crates/ruma-macros/src/serde.rs @@ -7,7 +7,7 @@ pub mod display_as_ref_str; pub mod enum_as_ref_str; pub mod enum_from_string; pub mod eq_as_ref_str; +pub mod incoming; pub mod ord_as_ref_str; -pub mod outgoing; pub mod serialize_as_ref_str; mod util; diff --git a/crates/ruma-macros/src/serde/outgoing.rs b/crates/ruma-macros/src/serde/incoming.rs similarity index 98% rename from crates/ruma-macros/src/serde/outgoing.rs rename to crates/ruma-macros/src/serde/incoming.rs index ccf0f0a1..b0ff42b1 100644 --- a/crates/ruma-macros/src/serde/outgoing.rs +++ b/crates/ruma-macros/src/serde/incoming.rs @@ -22,7 +22,7 @@ enum DataKind { Unit, } -pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result { +pub fn expand_derive_incoming(input: DeriveInput) -> syn::Result { let ruma_common = import_ruma_common(); let mut derives = vec![quote! { Debug }]; @@ -56,7 +56,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result { input.attrs.iter().filter(|attr| filter_input_attrs(attr)).collect::>(); let data = match input.data.clone() { - Data::Union(_) => panic!("#[derive(Outgoing)] does not support Union types"), + Data::Union(_) => panic!("#[derive(Incoming)] does not support Union types"), Data::Enum(e) => DataKind::Enum(e.variants.into_iter().collect()), Data::Struct(s) => match s.fields { Fields::Named(fs) => { 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 2c573cf8..9823f7bf 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification.rs @@ -13,7 +13,7 @@ pub mod v1 { api::ruma_api, events::RoomEventType, push::{PusherData, Tweak}, - serde::{Outgoing, StringEnum}, + serde::{Incoming, StringEnum}, EventId, RoomAliasId, RoomId, RoomName, SecondsSinceUnixEpoch, UserId, }; use serde::{Deserialize, Serialize}; @@ -65,7 +65,7 @@ pub mod v1 { } /// Type for passing information about a push notification - #[derive(Clone, Debug, Default, Outgoing, Serialize)] + #[derive(Clone, Debug, Default, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Notification<'a> { /// The Matrix event ID of the event being notified about. @@ -196,7 +196,7 @@ pub mod v1 { } /// Type for passing information about devices. - #[derive(Clone, Debug, Deserialize, Outgoing, Serialize)] + #[derive(Clone, Debug, Deserialize, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Device { /// The `app_id` given when the pusher was created. diff --git a/crates/ruma/src/lib.rs b/crates/ruma/src/lib.rs index 8d14f42e..fe98a26f 100644 --- a/crates/ruma/src/lib.rs +++ b/crates/ruma/src/lib.rs @@ -162,7 +162,7 @@ pub use ruma_client::Client; pub use ruma_common::{ authentication, device_id, device_key_id, directory, encryption, event_id, matrix_uri, mxc_uri, power_levels, presence, push, receipt, room, room_alias_id, room_id, room_version_id, - serde::Outgoing, server_name, server_signing_key_id, thirdparty, to_device, user_id, + serde::Incoming, server_name, server_signing_key_id, thirdparty, to_device, user_id, ClientSecret, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, DeviceSignatures, DeviceSigningKeyId, EntitySignatures, EventEncryptionAlgorithm, EventId, KeyId, KeyName, MatrixToUri, MilliSecondsSinceUnixEpoch, MxcUri, PrivOwnedStr, RoomAliasId, RoomId, RoomOrAliasId, diff --git a/crates/ruma/tests/outgoing.rs b/crates/ruma/tests/outgoing.rs index 2bf0b69c..8cfb969b 100644 --- a/crates/ruma/tests/outgoing.rs +++ b/crates/ruma/tests/outgoing.rs @@ -4,7 +4,7 @@ #![allow(clippy::exhaustive_structs, clippy::redundant_allocation)] -use ruma::{Outgoing, UserId}; +use ruma::{Incoming, UserId}; #[allow(unused)] pub struct Thing<'t, T> { @@ -20,14 +20,14 @@ pub struct IncomingThing { } #[allow(unused)] -#[derive(Copy, Clone, Debug, Outgoing, serde::Serialize)] +#[derive(Copy, Clone, Debug, Incoming, serde::Serialize)] #[serde(crate = "serde")] pub struct OtherThing<'t> { pub some: &'t str, pub t: &'t [u8], } -#[derive(Outgoing)] +#[derive(Incoming)] #[incoming_derive(!Deserialize)] #[non_exhaustive] pub struct FakeRequest<'a, T> { @@ -45,7 +45,7 @@ pub struct FakeRequest<'a, T> { pub triple_ref: &'a &'a &'a str, } -#[derive(Outgoing)] +#[derive(Incoming)] #[incoming_derive(!Deserialize)] #[non_exhaustive] pub enum EnumThing<'a, T> {