Mark macro-generated trait implementations as #[automatically_derived]
This commit is contained in:
parent
95d21552e0
commit
212153ea5f
@ -231,10 +231,12 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
TokenStream::new()
|
||||
} else {
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #request_lifetimes #ruma_api::OutgoingNonAuthRequest
|
||||
for Request #request_lifetimes
|
||||
{}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_api::IncomingNonAuthRequest for #incoming_request_type {}
|
||||
}
|
||||
};
|
||||
@ -246,10 +248,10 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
#[doc = #response_doc]
|
||||
#response_type
|
||||
|
||||
#[automatically_derived]
|
||||
impl ::std::convert::TryFrom<Response> for #http::Response<Vec<u8>> {
|
||||
type Error = #ruma_api::error::IntoHttpError;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn try_from(response: Response) -> ::std::result::Result<Self, Self::Error> {
|
||||
let mut resp_builder = #http::Response::builder()
|
||||
.header(#http::header::CONTENT_TYPE, "application/json");
|
||||
@ -267,10 +269,10 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl ::std::convert::TryFrom<#http::Response<Vec<u8>>> for Response {
|
||||
type Error = #ruma_api::error::FromHttpResponseError<#error>;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn try_from(
|
||||
response: #http::Response<Vec<u8>>,
|
||||
) -> ::std::result::Result<Self, Self::Error> {
|
||||
@ -303,6 +305,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
authentication: #ruma_api::AuthScheme::#authentication,
|
||||
};
|
||||
|
||||
#[automatically_derived]
|
||||
impl #request_lifetimes #ruma_api::OutgoingRequest for Request #request_lifetimes {
|
||||
type EndpointError = #error;
|
||||
type IncomingResponse = <Response as #ruma_serde::Outgoing>::Incoming;
|
||||
@ -310,7 +313,6 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
#[doc = #metadata_doc]
|
||||
const METADATA: #ruma_api::Metadata = self::METADATA;
|
||||
|
||||
#[allow(unused_mut, unused_variables)]
|
||||
fn try_into_http_request(
|
||||
self,
|
||||
base_url: &::std::primitive::str,
|
||||
@ -340,6 +342,7 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_api::IncomingRequest for #incoming_request_type {
|
||||
type EndpointError = #error;
|
||||
type OutgoingResponse = Response;
|
||||
@ -347,7 +350,6 @@ pub fn expand_all(api: Api) -> syn::Result<TokenStream> {
|
||||
#[doc = #metadata_doc]
|
||||
const METADATA: #ruma_api::Metadata = self::METADATA;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn try_from_http_request(
|
||||
request: #http::Request<Vec<u8>>
|
||||
) -> ::std::result::Result<Self, #ruma_api::error::FromHttpRequestError> {
|
||||
|
@ -108,6 +108,7 @@ fn expand_serialize_event(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gen #serde::ser::Serialize for #ident #ty_gen #where_clause {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -269,6 +270,7 @@ fn expand_deserialize_event(
|
||||
};
|
||||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #deserialize_impl_gen #serde::de::Deserialize<'de> for #ident #ty_gen #where_clause {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@ -289,6 +291,7 @@ fn expand_deserialize_event(
|
||||
/// the `content` and `prev_content` fields.
|
||||
struct EventVisitor #impl_generics (#deserialize_phantom_type #ty_gen);
|
||||
|
||||
#[automatically_derived]
|
||||
impl #deserialize_impl_gen #serde::de::Visitor<'de>
|
||||
for EventVisitor #ty_gen #where_clause
|
||||
{
|
||||
@ -379,6 +382,7 @@ fn expand_from_into(
|
||||
if let EventKindVariation::Sync | EventKindVariation::RedactedSync = var {
|
||||
let full_struct = kind.to_event_ident(&var.to_full_variation());
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_generics From<#full_struct #ty_gen> for #ident #ty_gen #where_clause {
|
||||
fn from(event: #full_struct #ty_gen) -> Self {
|
||||
let #full_struct {
|
||||
@ -388,6 +392,7 @@ fn expand_from_into(
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_generics #ident #ty_gen #where_clause {
|
||||
/// Convert this sync event into a full event, one with a room_id field.
|
||||
pub fn into_full_event(
|
||||
@ -414,6 +419,7 @@ fn expand_eq_ord_event(input: &DeriveInput, fields: &[Field]) -> Option<TokenStr
|
||||
let (impl_gen, ty_gen, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gen ::std::cmp::PartialEq for #ident #ty_gen #where_clause {
|
||||
/// This checks if two `EventId`s are equal.
|
||||
fn eq(&self, other: &Self) -> ::std::primitive::bool {
|
||||
@ -421,8 +427,10 @@ fn expand_eq_ord_event(input: &DeriveInput, fields: &[Field]) -> Option<TokenStr
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gen ::std::cmp::Eq for #ident #ty_gen #where_clause {}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gen ::std::cmp::PartialOrd for #ident #ty_gen #where_clause {
|
||||
/// This compares `EventId`s and orders them lexicographically.
|
||||
fn partial_cmp(&self, other: &Self) -> ::std::option::Option<::std::cmp::Ordering> {
|
||||
@ -430,6 +438,7 @@ fn expand_eq_ord_event(input: &DeriveInput, fields: &[Field]) -> Option<TokenStr
|
||||
}
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gen ::std::cmp::Ord for #ident #ty_gen #where_clause {
|
||||
/// This compares `EventId`s and orders them lexicographically.
|
||||
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
|
||||
|
@ -179,6 +179,7 @@ pub fn expand_event_content(
|
||||
|
||||
quote! {
|
||||
// this is the non redacted event content's impl
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
/// Transforms the full event content into a redacted content according to spec.
|
||||
pub fn redact(self, version: #ruma_identifiers::RoomVersionId) -> #redacted_ident {
|
||||
@ -194,6 +195,7 @@ pub fn expand_event_content(
|
||||
|
||||
#redacted_event_content
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RedactedEventContent for #redacted_ident {
|
||||
fn empty(ev_type: &str) -> Result<Self, #serde_json::Error> {
|
||||
if ev_type != #event_type {
|
||||
@ -238,6 +240,7 @@ pub fn expand_basic_event_content(
|
||||
Ok(quote! {
|
||||
#event_content_impl
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::BasicEventContent for #ident {}
|
||||
})
|
||||
}
|
||||
@ -253,6 +256,7 @@ pub fn expand_ephemeral_room_event_content(
|
||||
Ok(quote! {
|
||||
#event_content_impl
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::EphemeralRoomEventContent for #ident {}
|
||||
})
|
||||
}
|
||||
@ -268,6 +272,7 @@ pub fn expand_room_event_content(
|
||||
Ok(quote! {
|
||||
#event_content_impl
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RoomEventContent for #ident {}
|
||||
})
|
||||
}
|
||||
@ -283,6 +288,7 @@ pub fn expand_message_event_content(
|
||||
let redacted_marker_trait = if needs_redacted_from_input(input) {
|
||||
let ident = format_ident!("Redacted{}", &ident);
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RedactedMessageEventContent for #ident {}
|
||||
}
|
||||
} else {
|
||||
@ -292,6 +298,7 @@ pub fn expand_message_event_content(
|
||||
Ok(quote! {
|
||||
#room_ev_content
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::MessageEventContent for #ident {}
|
||||
|
||||
#redacted_marker_trait
|
||||
@ -309,6 +316,7 @@ pub fn expand_state_event_content(
|
||||
let redacted_marker_trait = if needs_redacted_from_input(input) {
|
||||
let ident = format_ident!("Redacted{}", input.ident);
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RedactedStateEventContent for #ident {}
|
||||
}
|
||||
} else {
|
||||
@ -318,6 +326,7 @@ pub fn expand_state_event_content(
|
||||
Ok(quote! {
|
||||
#room_ev_content
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::StateEventContent for #ident {}
|
||||
|
||||
#redacted_marker_trait
|
||||
@ -333,6 +342,7 @@ fn generate_event_content_impl(
|
||||
let serde_json = quote! { #ruma_events::exports::serde_json };
|
||||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::EventContent for #ident {
|
||||
fn event_type(&self) -> &str {
|
||||
#event_type
|
||||
|
@ -287,6 +287,7 @@ fn expand_conversion_impl(
|
||||
};
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
/// Convert this sync event into a full event, one with a room_id field.
|
||||
pub fn into_full_event(
|
||||
@ -399,6 +400,7 @@ fn expand_content_enum(
|
||||
let variant_ctors = variants.iter().map(|v| v.ctor(quote!(Self)));
|
||||
|
||||
let event_content_impl = quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::EventContent for #ident {
|
||||
fn event_type(&self) -> &str {
|
||||
match self {
|
||||
@ -487,6 +489,7 @@ fn expand_redact(
|
||||
let fields = quote! { #( #fields )* };
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
/// Redacts `Self` given a valid `Redaction[Sync]Event`.
|
||||
pub fn redact(
|
||||
@ -663,17 +666,23 @@ fn marker_traits(kind: &EventKind, ruma_events: &TokenStream) -> TokenStream {
|
||||
let ident = kind.to_content_enum();
|
||||
match kind {
|
||||
EventKind::State => quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RoomEventContent for #ident {}
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::StateEventContent for #ident {}
|
||||
},
|
||||
EventKind::Message => quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RoomEventContent for #ident {}
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::MessageEventContent for #ident {}
|
||||
},
|
||||
EventKind::Ephemeral => quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::EphemeralRoomEventContent for #ident {}
|
||||
},
|
||||
EventKind::Basic => quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::BasicEventContent for #ident {}
|
||||
},
|
||||
_ => TokenStream::new(),
|
||||
@ -735,6 +744,7 @@ fn accessor_methods(
|
||||
};
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
#content
|
||||
|
||||
@ -777,6 +787,7 @@ fn redacted_accessor_methods(
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
#( #methods )*
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use quote::quote;
|
||||
|
||||
pub fn expand_display_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
|
||||
Ok(quote! {
|
||||
#[automatically_derived]
|
||||
impl ::std::fmt::Display for #ident {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
f.write_str(<Self as ::std::convert::AsRef<::std::primitive::str>>::as_ref(self))
|
||||
|
@ -49,6 +49,7 @@ pub fn expand_enum_as_ref_str(input: &ItemEnum) -> syn::Result<TokenStream> {
|
||||
.collect::<syn::Result<_>>()?;
|
||||
|
||||
Ok(quote! {
|
||||
#[automatically_derived]
|
||||
impl ::std::convert::AsRef<::std::primitive::str> for #enum_name {
|
||||
fn as_ref(&self) -> &::std::primitive::str {
|
||||
match self { #(#branches),* }
|
||||
|
@ -101,6 +101,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||
#( #input_attrs )*
|
||||
#vis enum #incoming_ident #ty_gen { #( #vars, )* }
|
||||
|
||||
#[automatically_derived]
|
||||
impl #original_impl_gen #ruma_serde::Outgoing for #original_ident #original_ty_gen {
|
||||
type Incoming = #incoming_ident #impl_gen;
|
||||
}
|
||||
@ -142,6 +143,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||
#( #input_attrs )*
|
||||
#vis struct #incoming_ident #ty_gen #struct_def
|
||||
|
||||
#[automatically_derived]
|
||||
impl #original_impl_gen #ruma_serde::Outgoing for #original_ident #original_ty_gen {
|
||||
type Incoming = #incoming_ident #impl_gen;
|
||||
}
|
||||
@ -164,6 +166,7 @@ fn impl_outgoing_with_incoming_self(input: &DeriveInput, ruma_serde: &TokenStrea
|
||||
let (impl_gen, ty_gen, _) = input.generics.split_for_impl();
|
||||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gen #ruma_serde::Outgoing for #ident #ty_gen {
|
||||
type Incoming = Self;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ pub fn expand_serialize_as_ref_str(ident: &Ident) -> syn::Result<TokenStream> {
|
||||
let ruma_serde = import_ruma_serde();
|
||||
|
||||
Ok(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ruma_serde::exports::serde::ser::Serialize for #ident {
|
||||
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
|
Loading…
x
Reference in New Issue
Block a user