serde: Remove the Outgoing trait
This commit is contained in:
parent
4e7eeb8aa4
commit
5cf42f3a86
@ -268,10 +268,6 @@ pub mod v3 {
|
|||||||
extra: JsonObject,
|
extra: JsonObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Outgoing for CustomLoginInfo<'_> {
|
|
||||||
type Incoming = IncomingCustomLoginInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Client configuration provided by the server.
|
/// Client configuration provided by the server.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
@ -560,10 +560,6 @@ pub struct IncomingCustomAuthData {
|
|||||||
extra: JsonObject,
|
extra: JsonObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Outgoing for CustomAuthData<'_> {
|
|
||||||
type Incoming = IncomingCustomAuthData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Identification information for the user.
|
/// Identification information for the user.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||||
#[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")]
|
#[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")]
|
||||||
|
@ -72,22 +72,6 @@ where
|
|||||||
serde_json::from_str(val.get()).map_err(E::custom)
|
serde_json::from_str(val.get()).map_err(E::custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type that can be sent to another party that understands the matrix protocol.
|
|
||||||
///
|
|
||||||
/// If any of the fields of `Self` don't implement serde's `Deserialize`, you can derive this trait
|
|
||||||
/// to generate a corresponding 'Incoming' type that supports deserialization. This is useful for
|
|
||||||
/// things like `ruma_common::events::EventResult`. For more details, see the
|
|
||||||
/// [derive macro's documentation][doc].
|
|
||||||
///
|
|
||||||
/// [doc]: derive.Outgoing.html
|
|
||||||
// TODO: Better explain how this trait relates to serde's traits
|
|
||||||
pub trait Outgoing {
|
|
||||||
/// The 'Incoming' variant of `Self`.
|
|
||||||
type Incoming;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- Everything below is macro-related --
|
|
||||||
|
|
||||||
pub use ruma_macros::{
|
pub use ruma_macros::{
|
||||||
AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, Outgoing,
|
AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, Outgoing,
|
||||||
PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde,
|
PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde,
|
||||||
|
@ -12,7 +12,6 @@ use ruma_common::{
|
|||||||
AuthScheme, EndpointError, IncomingRequest, IncomingResponse, MatrixVersion, Metadata,
|
AuthScheme, EndpointError, IncomingRequest, IncomingResponse, MatrixVersion, Metadata,
|
||||||
OutgoingRequest, OutgoingResponse, SendAccessToken,
|
OutgoingRequest, OutgoingResponse, SendAccessToken,
|
||||||
},
|
},
|
||||||
serde::Outgoing,
|
|
||||||
RoomAliasId, RoomId,
|
RoomAliasId, RoomId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -24,10 +23,6 @@ pub struct Request {
|
|||||||
pub room_alias: Box<RoomAliasId>, // path
|
pub room_alias: Box<RoomAliasId>, // path
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Outgoing for Request {
|
|
||||||
type Incoming = Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
const METADATA: Metadata = Metadata {
|
const METADATA: Metadata = Metadata {
|
||||||
description: "Add an alias to a room.",
|
description: "Add an alias to a room.",
|
||||||
method: Method::PUT,
|
method: Method::PUT,
|
||||||
@ -116,10 +111,6 @@ struct RequestBody {
|
|||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Response;
|
pub struct Response;
|
||||||
|
|
||||||
impl Outgoing for Response {
|
|
||||||
type Incoming = Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IncomingResponse for Response {
|
impl IncomingResponse for Response {
|
||||||
type EndpointError = MatrixError;
|
type EndpointError = MatrixError;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match data {
|
match data {
|
||||||
DataKind::Unit => Ok(impl_outgoing_with_incoming_self(&input, &ruma_common)),
|
DataKind::Unit => Ok(TokenStream::new()),
|
||||||
DataKind::Enum(mut vars) => {
|
DataKind::Enum(mut vars) => {
|
||||||
let mut found_lifetime = false;
|
let mut found_lifetime = false;
|
||||||
for var in &mut vars {
|
for var in &mut vars {
|
||||||
@ -81,30 +81,21 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let original_ident = &input.ident;
|
|
||||||
let (original_impl_gen, original_ty_gen, _) = input.generics.split_for_impl();
|
|
||||||
|
|
||||||
if !found_lifetime {
|
if !found_lifetime {
|
||||||
return Ok(impl_outgoing_with_incoming_self(&input, &ruma_common));
|
return Ok(TokenStream::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis = input.vis;
|
let vis = input.vis;
|
||||||
let doc = format!("'Incoming' variant of [{ty}](enum.{ty}.html).", ty = &input.ident);
|
let doc = format!("'Incoming' variant of [{ty}](enum.{ty}.html).", ty = &input.ident);
|
||||||
let incoming_ident =
|
let incoming_ident = format_ident!("Incoming{}", input.ident, span = Span::call_site());
|
||||||
format_ident!("Incoming{}", original_ident, span = Span::call_site());
|
|
||||||
let mut gen_copy = input.generics.clone();
|
let mut gen_copy = input.generics.clone();
|
||||||
let (impl_gen, ty_gen) = split_for_impl_lifetime_less(&mut gen_copy);
|
let (_, ty_gen) = split_for_impl_lifetime_less(&mut gen_copy);
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
#[derive( #( #derives ),* )]
|
#[derive( #( #derives ),* )]
|
||||||
#( #input_attrs )*
|
#( #input_attrs )*
|
||||||
#vis enum #incoming_ident #ty_gen { #( #vars, )* }
|
#vis enum #incoming_ident #ty_gen { #( #vars, )* }
|
||||||
|
|
||||||
#[automatically_derived]
|
|
||||||
impl #original_impl_gen #ruma_common::serde::Outgoing for #original_ident #original_ty_gen {
|
|
||||||
type Incoming = #incoming_ident #impl_gen;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
DataKind::Struct(mut fields, struct_kind) => {
|
DataKind::Struct(mut fields, struct_kind) => {
|
||||||
@ -118,19 +109,15 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let original_ident = &input.ident;
|
|
||||||
let (original_impl_gen, original_ty_gen, _) = input.generics.split_for_impl();
|
|
||||||
|
|
||||||
if !found_lifetime {
|
if !found_lifetime {
|
||||||
return Ok(impl_outgoing_with_incoming_self(&input, &ruma_common));
|
return Ok(TokenStream::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis = input.vis;
|
let vis = input.vis;
|
||||||
let doc = format!("'Incoming' variant of [{ty}](struct.{ty}.html).", ty = &input.ident);
|
let doc = format!("'Incoming' variant of [{ty}](struct.{ty}.html).", ty = &input.ident);
|
||||||
let incoming_ident =
|
let incoming_ident = format_ident!("Incoming{}", input.ident, span = Span::call_site());
|
||||||
format_ident!("Incoming{}", original_ident, span = Span::call_site());
|
|
||||||
let mut gen_copy = input.generics.clone();
|
let mut gen_copy = input.generics.clone();
|
||||||
let (impl_gen, ty_gen) = split_for_impl_lifetime_less(&mut gen_copy);
|
let (_, ty_gen) = split_for_impl_lifetime_less(&mut gen_copy);
|
||||||
|
|
||||||
let struct_def = match struct_kind {
|
let struct_def = match struct_kind {
|
||||||
StructKind::Struct => quote! { { #(#fields,)* } },
|
StructKind::Struct => quote! { { #(#fields,)* } },
|
||||||
@ -142,11 +129,6 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
#[derive( #( #derives ),* )]
|
#[derive( #( #derives ),* )]
|
||||||
#( #input_attrs )*
|
#( #input_attrs )*
|
||||||
#vis struct #incoming_ident #ty_gen #struct_def
|
#vis struct #incoming_ident #ty_gen #struct_def
|
||||||
|
|
||||||
#[automatically_derived]
|
|
||||||
impl #original_impl_gen #ruma_common::serde::Outgoing for #original_ident #original_ty_gen {
|
|
||||||
type Incoming = #incoming_ident #impl_gen;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,18 +144,6 @@ fn filter_input_attrs(attr: &Attribute) -> bool {
|
|||||||
|| attr.path.is_ident("allow")
|
|| attr.path.is_ident("allow")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_outgoing_with_incoming_self(input: &DeriveInput, ruma_common: &TokenStream) -> TokenStream {
|
|
||||||
let ident = &input.ident;
|
|
||||||
let (impl_gen, ty_gen, _) = input.generics.split_for_impl();
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#[automatically_derived]
|
|
||||||
impl #impl_gen #ruma_common::serde::Outgoing for #ident #ty_gen {
|
|
||||||
type Incoming = Self;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn split_for_impl_lifetime_less(generics: &mut Generics) -> (ImplGenerics<'_>, TypeGenerics<'_>) {
|
fn split_for_impl_lifetime_less(generics: &mut Generics) -> (ImplGenerics<'_>, TypeGenerics<'_>) {
|
||||||
generics.params = generics
|
generics.params = generics
|
||||||
.params
|
.params
|
||||||
|
Loading…
x
Reference in New Issue
Block a user