serde: Rename derive macro Outgoing to Incoming

All it does now is generate `Incoming{Self}` types.
This commit is contained in:
Jonas Platte 2022-03-21 15:49:00 +01:00 committed by Jonas Platte
parent 5cf42f3a86
commit a6a530dcc8
25 changed files with 68 additions and 110 deletions

View File

@ -19,13 +19,13 @@ pub mod request_registration_token_via_msisdn;
pub mod unbind_3pid; pub mod unbind_3pid;
pub mod whoami; pub mod whoami;
use ruma_common::serde::{Outgoing, StringEnum}; use ruma_common::serde::{Incoming, StringEnum};
use serde::Serialize; use serde::Serialize;
use crate::PrivOwnedStr; use crate::PrivOwnedStr;
/// Additional authentication information for requestToken endpoints. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct IdentityServerInfo<'a> { pub struct IdentityServerInfo<'a> {
/// The ID server to send the onward request to as a hostname with an /// The ID server to send the onward request to as a hostname with an

View File

@ -8,7 +8,7 @@ mod url;
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
serde::{Outgoing, StringEnum}, serde::{Incoming, StringEnum},
RoomId, UserId, RoomId, UserId,
}; };
use serde::Serialize; use serde::Serialize;
@ -83,7 +83,7 @@ impl RelationType {
} }
/// Filters to be applied to room events. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Clone, Default, Serialize)] #[incoming_derive(Clone, Default, Serialize)]
pub struct RoomEventFilter<'a> { pub struct RoomEventFilter<'a> {
@ -228,7 +228,7 @@ impl IncomingRoomEventFilter {
} }
/// Filters to be applied to room data. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Clone, Default, Serialize)] #[incoming_derive(Clone, Default, Serialize)]
pub struct RoomFilter<'a> { pub struct RoomFilter<'a> {
@ -310,7 +310,7 @@ impl IncomingRoomFilter {
} }
/// Filter for non-room data. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Clone, Default, Serialize)] #[incoming_derive(Clone, Default, Serialize)]
pub struct Filter<'a> { pub struct Filter<'a> {
@ -382,7 +382,7 @@ impl IncomingFilter {
} }
/// A filter definition /// A filter definition
#[derive(Clone, Debug, Default, Outgoing, Serialize)] #[derive(Clone, Debug, Default, Incoming, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Clone, Default, Serialize)] #[incoming_derive(Clone, Default, Serialize)]
pub struct FilterDefinition<'a> { pub struct FilterDefinition<'a> {

View File

@ -14,12 +14,12 @@ pub mod unban_user;
use std::collections::BTreeMap; 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; use serde::Serialize;
/// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// 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. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ThirdPartySigned<'a> { pub struct ThirdPartySigned<'a> {
/// The Matrix ID of the user who issued the invite. /// 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 /// To create an instance of this type, first create a `Invite3pidInit` and convert it via
/// `Invite3pid::from` / `.into()`. /// `Invite3pid::from` / `.into()`.
#[derive(Clone, Debug, PartialEq, Outgoing, Serialize)] #[derive(Clone, Debug, PartialEq, Incoming, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(PartialEq)] #[incoming_derive(PartialEq)]
pub struct Invite3pid<'a> { pub struct Invite3pid<'a> {

View File

@ -10,7 +10,7 @@ pub mod v3 {
//! [spec-mxid]: https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite //! [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 //! [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 serde::Serialize;
use crate::membership::{IncomingInvite3pid, Invite3pid}; use crate::membership::{IncomingInvite3pid, Invite3pid};
@ -62,7 +62,7 @@ pub mod v3 {
} }
/// Distinguishes between invititations by Matrix or third party identifiers. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(PartialEq)] #[incoming_derive(PartialEq)]
#[serde(untagged)] #[serde(untagged)]

View File

@ -11,7 +11,7 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::ruma_api, api::ruma_api,
events::{AnyRoomEvent, AnyStateEvent}, events::{AnyRoomEvent, AnyStateEvent},
serde::{Outgoing, Raw, StringEnum}, serde::{Incoming, Raw, StringEnum},
EventId, MxcUri, RoomId, UserId, EventId, MxcUri, RoomId, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -67,7 +67,7 @@ pub mod v3 {
} }
/// Categories of events that can be searched for. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Categories<'a> { pub struct Categories<'a> {
/// Criteria for searching room events. /// Criteria for searching room events.
@ -83,7 +83,7 @@ pub mod v3 {
} }
/// Criteria for searching a category of events. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Criteria<'a> { pub struct Criteria<'a> {
/// The string to search events for. /// 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. /// 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)] #[incoming_derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Groupings<'a> { pub struct Groupings<'a> {

View File

@ -7,7 +7,7 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::ruma_api, api::ruma_api,
serde::{JsonObject, Outgoing}, serde::{Incoming, JsonObject},
DeviceId, ServerName, UserId, DeviceId, ServerName, UserId,
}; };
use serde::{ use serde::{
@ -94,7 +94,7 @@ pub mod v3 {
/// ///
/// To construct the custom `LoginInfo` variant you first have to construct /// To construct the custom `LoginInfo` variant you first have to construct
/// [`IncomingLoginInfo::new`] and then call [`IncomingLoginInfo::to_outgoing`] on it. /// [`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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
#[serde(untagged)] #[serde(untagged)]
@ -177,7 +177,7 @@ pub mod v3 {
} }
/// An identifier and password to supply as authentication. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.password")] #[serde(tag = "type", rename = "m.login.password")]
pub struct Password<'a> { pub struct Password<'a> {
@ -203,7 +203,7 @@ pub mod v3 {
} }
/// A token to supply as authentication. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.token")] #[serde(tag = "type", rename = "m.login.token")]
pub struct Token<'a> { pub struct Token<'a> {
@ -226,7 +226,7 @@ pub mod v3 {
} }
/// An identifier to supply for Application Service authentication. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.application_service")] #[serde(tag = "type", rename = "m.login.application_service")]
pub struct ApplicationService<'a> { pub struct ApplicationService<'a> {

View File

@ -8,7 +8,7 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::ruma_api, api::ruma_api,
events::{AnyStateEventContent, StateEventType}, events::{AnyStateEventContent, StateEventType},
serde::{Outgoing, Raw}, serde::{Incoming, Raw},
RoomId, RoomId,
}; };
@ -39,7 +39,7 @@ pub mod v3 {
/// Data for a request to the `get_state_events_for_key` API endpoint. /// Data for a request to the `get_state_events_for_key` API endpoint.
/// ///
/// Get state events associated with a given key. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
pub struct Request<'a> { pub struct Request<'a> {

View File

@ -8,7 +8,7 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::ruma_api, api::ruma_api,
events::{AnyStateEventContent, EventContent, StateEventType}, events::{AnyStateEventContent, EventContent, StateEventType},
serde::{Outgoing, Raw}, serde::{Incoming, Raw},
EventId, RoomId, EventId, RoomId,
}; };
use serde_json::value::to_raw_value as to_raw_json_value; 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. /// Data for a request to the `send_state_event` API endpoint.
/// ///
/// Send a state event to a room associated with a given state key. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
pub struct Request<'a> { pub struct Request<'a> {

View File

@ -16,7 +16,7 @@ pub mod v3 {
AnyToDeviceEvent, AnyToDeviceEvent,
}, },
presence::PresenceState, presence::PresenceState,
serde::{Outgoing, Raw}, serde::{Incoming, Raw},
DeviceKeyAlgorithm, RoomId, UserId, DeviceKeyAlgorithm, RoomId, UserId,
}; };
use serde::{Deserialize, Serialize}; 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. /// 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)] #[allow(clippy::large_enum_variant)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(untagged)] #[serde(untagged)]

View File

@ -10,7 +10,7 @@ use ruma_common::{
error::{DeserializationError, IntoHttpError}, error::{DeserializationError, IntoHttpError},
EndpointError, OutgoingResponse, EndpointError, OutgoingResponse,
}, },
serde::{from_raw_json_value, JsonObject, Outgoing, StringEnum}, serde::{from_raw_json_value, Incoming, JsonObject, StringEnum},
thirdparty::Medium, thirdparty::Medium,
ClientSecret, SessionId, ClientSecret, SessionId,
}; };
@ -34,7 +34,7 @@ mod user_serde;
/// ///
/// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`] /// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`]
/// and then call [`IncomingAuthData::to_outgoing`] on it. /// and then call [`IncomingAuthData::to_outgoing`] on it.
#[derive(Clone, Debug, Outgoing, Serialize)] #[derive(Clone, Debug, Incoming, Serialize)]
#[non_exhaustive] #[non_exhaustive]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
#[serde(untagged)] #[serde(untagged)]
@ -342,7 +342,7 @@ pub enum AuthType {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#password-based /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.password")] #[serde(tag = "type", rename = "m.login.password")]
pub struct Password<'a> { pub struct Password<'a> {
@ -379,7 +379,7 @@ impl IncomingPassword {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#google-recaptcha /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.recaptcha")] #[serde(tag = "type", rename = "m.login.recaptcha")]
pub struct ReCaptcha<'a> { pub struct ReCaptcha<'a> {
@ -409,7 +409,7 @@ impl IncomingReCaptcha {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#email-based-identity--homeserver /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.email.identity")] #[serde(tag = "type", rename = "m.login.email.identity")]
pub struct EmailIdentity<'a> { pub struct EmailIdentity<'a> {
@ -436,7 +436,7 @@ impl IncomingEmailIdentity {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#phone-numbermsisdn-based-identity--homeserver /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.msisdn")] #[serde(tag = "type", rename = "m.login.msisdn")]
pub struct Msisdn<'a> { pub struct Msisdn<'a> {
@ -460,7 +460,7 @@ impl IncomingMsisdn {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#dummy-auth /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.dummy")] #[serde(tag = "type", rename = "m.login.dummy")]
pub struct Dummy<'a> { pub struct Dummy<'a> {
@ -487,7 +487,7 @@ impl IncomingDummy {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#token-authenticated-registration /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "type", rename = "m.login.registration_token")] #[serde(tag = "type", rename = "m.login.registration_token")]
pub struct RegistrationToken<'a> { pub struct RegistrationToken<'a> {
@ -517,7 +517,7 @@ impl IncomingRegistrationToken {
/// See [the spec] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [the spec]: https://spec.matrix.org/v1.2/client-server-api/#fallback /// [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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct FallbackAcknowledgement<'a> { pub struct FallbackAcknowledgement<'a> {
/// The value of the session key given by the homeserver. /// The value of the session key given by the homeserver.
@ -561,7 +561,7 @@ pub struct IncomingCustomAuthData {
} }
/// Identification information for the user. /// 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<'_>")] #[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")]
#[allow(clippy::exhaustive_enums)] #[allow(clippy::exhaustive_enums)]
pub enum UserIdentifier<'a> { pub enum UserIdentifier<'a> {

View File

@ -1,12 +1,12 @@
//! Helper module for the Serialize / Deserialize impl's for the User struct //! Helper module for the Serialize / Deserialize impl's for the User struct
//! in the parent module. //! in the parent module.
use ruma_common::{serde::Outgoing, thirdparty::Medium}; use ruma_common::{serde::Incoming, thirdparty::Medium};
use serde::Serialize; use serde::Serialize;
// The following structs could just be used in place of the one in the parent module, but // 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. // 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")] #[serde(tag = "type")]
pub(crate) enum UserIdentifier<'a> { pub(crate) enum UserIdentifier<'a> {
#[serde(rename = "m.id.user")] #[serde(rename = "m.id.user")]

View File

@ -2,7 +2,7 @@
use std::fmt; use std::fmt;
use crate::serde::{Outgoing, StringEnum}; use crate::serde::{Incoming, StringEnum};
use js_int::UInt; use js_int::UInt;
use serde::{ use serde::{
de::{Error, MapAccess, Visitor}, de::{Error, MapAccess, Visitor},
@ -108,7 +108,7 @@ impl From<PublicRoomsChunkInit> for PublicRoomsChunk {
} }
/// A filter for public rooms lists /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Default)] #[incoming_derive(Default)]
pub struct Filter<'a> { pub struct Filter<'a> {
@ -131,7 +131,7 @@ impl Filter<'_> {
/// Information about which networks/protocols from application services on the /// Information about which networks/protocols from application services on the
/// homeserver from which to request rooms. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Clone, PartialEq, Eq, !Deserialize)] #[incoming_derive(Clone, PartialEq, Eq, !Deserialize)]
pub enum RoomNetwork<'a> { pub enum RoomNetwork<'a> {

View File

@ -73,6 +73,6 @@ where
} }
pub use ruma_macros::{ pub use ruma_macros::{
AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, Outgoing, AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, Incoming, OrdAsRefStr,
PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde, PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde,
}; };

View File

@ -1,6 +1,6 @@
#![allow(clippy::exhaustive_structs)] #![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 struct OtherThing<'t> {
pub some: &'t str, pub some: &'t str,
pub t: &'t [u8], pub t: &'t [u8],

View File

@ -4,7 +4,7 @@ use ruma_common::{
error::{FromHttpResponseError, IntoHttpError, MatrixError}, error::{FromHttpResponseError, IntoHttpError, MatrixError},
ruma_api, IncomingResponse, OutgoingResponse, ruma_api, IncomingResponse, OutgoingResponse,
}, },
serde::Outgoing, serde::Incoming,
}; };
ruma_api! { ruma_api! {
@ -25,7 +25,7 @@ ruma_api! {
} }
} }
#[derive(Outgoing)] #[derive(Incoming)]
pub struct Response; pub struct Response;
impl IncomingResponse for Response { impl IncomingResponse for Response {

View File

@ -99,7 +99,7 @@ impl Request {
Clone, Clone,
Debug, Debug,
#ruma_macros::Request, #ruma_macros::Request,
#ruma_common::serde::Outgoing, #ruma_common::serde::Incoming,
#ruma_common::serde::_FakeDeriveSerde, #ruma_common::serde::_FakeDeriveSerde,
)] )]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]

View File

@ -39,7 +39,7 @@ impl Response {
Clone, Clone,
Debug, Debug,
#ruma_macros::Response, #ruma_macros::Response,
#ruma_common::serde::Outgoing, #ruma_common::serde::Incoming,
#ruma_common::serde::_FakeDeriveSerde, #ruma_common::serde::_FakeDeriveSerde,
)] )]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]

View File

@ -220,7 +220,7 @@ impl Request {
#serde::Serialize, #serde::Serialize,
#derive_deserialize #derive_deserialize
)] )]
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Outgoing))] #[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
#serde_attr #serde_attr
struct RequestBody< #(#lifetimes),* > { #(#fields),* } struct RequestBody< #(#lifetimes),* > { #(#fields),* }
} }
@ -248,7 +248,7 @@ impl Request {
#serde::Serialize, #serde::Serialize,
#derive_deserialize #derive_deserialize
)] )]
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Outgoing))] #[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
struct RequestQuery< #(#lifetimes),* > #def struct RequestQuery< #(#lifetimes),* > #def
} }
}); });

View File

@ -110,7 +110,7 @@ impl Response {
#[derive( #[derive(
Debug, Debug,
#ruma_macros::_FakeDeriveRumaApi, #ruma_macros::_FakeDeriveRumaApi,
#ruma_common::serde::Outgoing, #ruma_common::serde::Incoming,
#serde_derives #serde_derives
)] )]
#serde_attr #serde_attr

View File

@ -37,8 +37,8 @@ use self::{
enum_as_ref_str::expand_enum_as_ref_str, enum_as_ref_str::expand_enum_as_ref_str,
enum_from_string::expand_enum_from_string, enum_from_string::expand_enum_from_string,
eq_as_ref_str::expand_partial_eq_as_ref_str, 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}, 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, serialize_as_ref_str::expand_serialize_as_ref_str,
}, },
util::import_ruma_common, util::import_ruma_common,
@ -232,55 +232,13 @@ pub fn user_id(input: TokenStream) -> TokenStream {
output.into() output.into()
} }
/// Derive the `Outgoing` trait, possibly generating an 'Incoming' version of the struct this /// Generating an 'Incoming' version of the type this derive macro is used on.
/// derive macro is used on.
/// ///
/// Specifically, if no lifetime variables are used on any of the fields of the struct, this simple /// This type will be a fully-owned version of the input type, using no lifetime generics.
/// implementation will be generated: #[proc_macro_derive(Incoming, attributes(incoming_derive))]
/// pub fn derive_incoming(input: TokenStream) -> TokenStream {
/// ```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<Baz>,
#[wrap_incoming(with EventResult)]
pub x: XEvent,
#[wrap_incoming(YEvent with EventResult)]
pub ys: Vec<YEvent>,
}
// generated
struct IncomingMyType {
pub foo: Foo,
pub bar: IncomingBar,
pub baz: Option<IncomingBaz>,
pub x: EventResult<XEvent>,
pub ys: Vec<EventResult<YEvent>>,
}
```
*/
#[proc_macro_derive(Outgoing, attributes(incoming_derive))]
pub fn derive_outgoing(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput); 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<str>` trait for an enum. /// Derive the `AsRef<str>` trait for an enum.

View File

@ -7,7 +7,7 @@ pub mod display_as_ref_str;
pub mod enum_as_ref_str; pub mod enum_as_ref_str;
pub mod enum_from_string; pub mod enum_from_string;
pub mod eq_as_ref_str; pub mod eq_as_ref_str;
pub mod incoming;
pub mod ord_as_ref_str; pub mod ord_as_ref_str;
pub mod outgoing;
pub mod serialize_as_ref_str; pub mod serialize_as_ref_str;
mod util; mod util;

View File

@ -22,7 +22,7 @@ enum DataKind {
Unit, Unit,
} }
pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> { pub fn expand_derive_incoming(input: DeriveInput) -> syn::Result<TokenStream> {
let ruma_common = import_ruma_common(); let ruma_common = import_ruma_common();
let mut derives = vec![quote! { Debug }]; let mut derives = vec![quote! { Debug }];
@ -56,7 +56,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
input.attrs.iter().filter(|attr| filter_input_attrs(attr)).collect::<Vec<_>>(); input.attrs.iter().filter(|attr| filter_input_attrs(attr)).collect::<Vec<_>>();
let data = match input.data.clone() { 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::Enum(e) => DataKind::Enum(e.variants.into_iter().collect()),
Data::Struct(s) => match s.fields { Data::Struct(s) => match s.fields {
Fields::Named(fs) => { Fields::Named(fs) => {

View File

@ -13,7 +13,7 @@ pub mod v1 {
api::ruma_api, api::ruma_api,
events::RoomEventType, events::RoomEventType,
push::{PusherData, Tweak}, push::{PusherData, Tweak},
serde::{Outgoing, StringEnum}, serde::{Incoming, StringEnum},
EventId, RoomAliasId, RoomId, RoomName, SecondsSinceUnixEpoch, UserId, EventId, RoomAliasId, RoomId, RoomName, SecondsSinceUnixEpoch, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -65,7 +65,7 @@ pub mod v1 {
} }
/// Type for passing information about a push notification /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Notification<'a> { pub struct Notification<'a> {
/// The Matrix event ID of the event being notified about. /// The Matrix event ID of the event being notified about.
@ -196,7 +196,7 @@ pub mod v1 {
} }
/// Type for passing information about devices. /// 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)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Device { pub struct Device {
/// The `app_id` given when the pusher was created. /// The `app_id` given when the pusher was created.

View File

@ -162,7 +162,7 @@ pub use ruma_client::Client;
pub use ruma_common::{ pub use ruma_common::{
authentication, device_id, device_key_id, directory, encryption, event_id, matrix_uri, mxc_uri, 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, 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, ClientSecret, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, DeviceSignatures, DeviceSigningKeyId,
EntitySignatures, EventEncryptionAlgorithm, EventId, KeyId, KeyName, MatrixToUri, EntitySignatures, EventEncryptionAlgorithm, EventId, KeyId, KeyName, MatrixToUri,
MilliSecondsSinceUnixEpoch, MxcUri, PrivOwnedStr, RoomAliasId, RoomId, RoomOrAliasId, MilliSecondsSinceUnixEpoch, MxcUri, PrivOwnedStr, RoomAliasId, RoomId, RoomOrAliasId,

View File

@ -4,7 +4,7 @@
#![allow(clippy::exhaustive_structs, clippy::redundant_allocation)] #![allow(clippy::exhaustive_structs, clippy::redundant_allocation)]
use ruma::{Outgoing, UserId}; use ruma::{Incoming, UserId};
#[allow(unused)] #[allow(unused)]
pub struct Thing<'t, T> { pub struct Thing<'t, T> {
@ -20,14 +20,14 @@ pub struct IncomingThing<T> {
} }
#[allow(unused)] #[allow(unused)]
#[derive(Copy, Clone, Debug, Outgoing, serde::Serialize)] #[derive(Copy, Clone, Debug, Incoming, serde::Serialize)]
#[serde(crate = "serde")] #[serde(crate = "serde")]
pub struct OtherThing<'t> { pub struct OtherThing<'t> {
pub some: &'t str, pub some: &'t str,
pub t: &'t [u8], pub t: &'t [u8],
} }
#[derive(Outgoing)] #[derive(Incoming)]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
#[non_exhaustive] #[non_exhaustive]
pub struct FakeRequest<'a, T> { pub struct FakeRequest<'a, T> {
@ -45,7 +45,7 @@ pub struct FakeRequest<'a, T> {
pub triple_ref: &'a &'a &'a str, pub triple_ref: &'a &'a &'a str,
} }
#[derive(Outgoing)] #[derive(Incoming)]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Deserialize)]
#[non_exhaustive] #[non_exhaustive]
pub enum EnumThing<'a, T> { pub enum EnumThing<'a, T> {