serde: Remove the Outgoing trait
This commit is contained in:
parent
4e7eeb8aa4
commit
5cf42f3a86
@ -268,10 +268,6 @@ pub mod v3 {
|
||||
extra: JsonObject,
|
||||
}
|
||||
|
||||
impl Outgoing for CustomLoginInfo<'_> {
|
||||
type Incoming = IncomingCustomLoginInfo;
|
||||
}
|
||||
|
||||
/// Client configuration provided by the server.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -560,10 +560,6 @@ pub struct IncomingCustomAuthData {
|
||||
extra: JsonObject,
|
||||
}
|
||||
|
||||
impl Outgoing for CustomAuthData<'_> {
|
||||
type Incoming = IncomingCustomAuthData;
|
||||
}
|
||||
|
||||
/// Identification information for the user.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing, Serialize)]
|
||||
#[serde(from = "user_serde::IncomingUserIdentifier", into = "user_serde::UserIdentifier<'_>")]
|
||||
|
@ -72,22 +72,6 @@ where
|
||||
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::{
|
||||
AsRefStr, DeserializeFromCowStr, DisplayAsRefStr, FromString, OrdAsRefStr, Outgoing,
|
||||
PartialEqAsRefStr, PartialOrdAsRefStr, SerializeAsRefStr, StringEnum, _FakeDeriveSerde,
|
||||
|
@ -12,7 +12,6 @@ use ruma_common::{
|
||||
AuthScheme, EndpointError, IncomingRequest, IncomingResponse, MatrixVersion, Metadata,
|
||||
OutgoingRequest, OutgoingResponse, SendAccessToken,
|
||||
},
|
||||
serde::Outgoing,
|
||||
RoomAliasId, RoomId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -24,10 +23,6 @@ pub struct Request {
|
||||
pub room_alias: Box<RoomAliasId>, // path
|
||||
}
|
||||
|
||||
impl Outgoing for Request {
|
||||
type Incoming = Self;
|
||||
}
|
||||
|
||||
const METADATA: Metadata = Metadata {
|
||||
description: "Add an alias to a room.",
|
||||
method: Method::PUT,
|
||||
@ -116,10 +111,6 @@ struct RequestBody {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Response;
|
||||
|
||||
impl Outgoing for Response {
|
||||
type Incoming = Self;
|
||||
}
|
||||
|
||||
impl IncomingResponse for Response {
|
||||
type EndpointError = MatrixError;
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||
};
|
||||
|
||||
match data {
|
||||
DataKind::Unit => Ok(impl_outgoing_with_incoming_self(&input, &ruma_common)),
|
||||
DataKind::Unit => Ok(TokenStream::new()),
|
||||
DataKind::Enum(mut vars) => {
|
||||
let mut found_lifetime = false;
|
||||
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 {
|
||||
return Ok(impl_outgoing_with_incoming_self(&input, &ruma_common));
|
||||
return Ok(TokenStream::new());
|
||||
}
|
||||
|
||||
let vis = input.vis;
|
||||
let doc = format!("'Incoming' variant of [{ty}](enum.{ty}.html).", ty = &input.ident);
|
||||
let incoming_ident =
|
||||
format_ident!("Incoming{}", original_ident, span = Span::call_site());
|
||||
let incoming_ident = format_ident!("Incoming{}", input.ident, span = Span::call_site());
|
||||
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! {
|
||||
#[doc = #doc]
|
||||
#[derive( #( #derives ),* )]
|
||||
#( #input_attrs )*
|
||||
#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) => {
|
||||
@ -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 {
|
||||
return Ok(impl_outgoing_with_incoming_self(&input, &ruma_common));
|
||||
return Ok(TokenStream::new());
|
||||
}
|
||||
|
||||
let vis = input.vis;
|
||||
let doc = format!("'Incoming' variant of [{ty}](struct.{ty}.html).", ty = &input.ident);
|
||||
let incoming_ident =
|
||||
format_ident!("Incoming{}", original_ident, span = Span::call_site());
|
||||
let incoming_ident = format_ident!("Incoming{}", input.ident, span = Span::call_site());
|
||||
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 {
|
||||
StructKind::Struct => quote! { { #(#fields,)* } },
|
||||
@ -142,11 +129,6 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||
#[derive( #( #derives ),* )]
|
||||
#( #input_attrs )*
|
||||
#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")
|
||||
}
|
||||
|
||||
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<'_>) {
|
||||
generics.params = generics
|
||||
.params
|
||||
|
Loading…
x
Reference in New Issue
Block a user