fn expand_content_enum(
    kind: &EventKind,
    events: &[LitStr],
    attrs: &[Attribute],
    variants: &[EventEnumVariant],
    ruma_events: &TokenStream,
) -> TokenStream {
    let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers };
    let serde = quote! { #ruma_events::exports::serde };
    let serde_json = quote! { #ruma_events::exports::serde_json };

    let ident = kind.to_content_enum();

    let event_type_str = events;

    let content: Vec<_> =
        events.iter().map(|ev| to_event_content_path(kind, ev, None, ruma_events)).collect();

    let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>();

    let content_enum = quote! {
        #( #attrs )*
        #[derive(Clone, Debug, #serde::Serialize)]
        #[serde(untagged)]
        #[allow(clippy::large_enum_variant)]
        pub enum #ident {
            #(
                #[doc = #event_type_str]
                #variant_decls(#content),
            )*
            /// Content of an event not defined by the Matrix specification.
            #[doc(hidden)]
            _Custom(#ruma_events::custom::CustomEventContent),
        }
    };

    let variant_attrs = variants.iter().map(|v| {
        let attrs = &v.attrs;
        quote! { #(#attrs)* }
    });
    let variant_arms = variants.iter().map(|v| v.match_arm(quote!(Self))).collect::<Vec<_>>();
    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) -> &::std::primitive::str {
                match self {
                    #( #variant_arms(content) => content.event_type(), )*
                    Self::_Custom(content) => content.event_type(),
                }
            }

            fn from_parts(
                event_type: &::std::primitive::str,
                input: &#serde_json::value::RawValue,
            ) -> #serde_json::Result<Self> {
                match event_type {
                    #(
                        #variant_attrs #event_type_str => {
                            let content = #content::from_parts(event_type, input)?;
                            ::std::result::Result::Ok(#variant_ctors(content))
                        },
                    )*
                    ev_type => {
                        let content =
                            #ruma_events::custom::CustomEventContent::from_parts(ev_type, input)?;
                        ::std::result::Result::Ok(Self::_Custom(content))
                    },
                }
            }
        }
    };

    let marker_trait_impl = marker_trait(kind, ruma_events);

    let redacted_content_enum = if kind.is_state() || kind.is_message() {
        let redacted_ident = kind.to_redacted_content_enum();
        let redaction_variants = variants.iter().map(|v| v.ctor(&redacted_ident));
        let redacted_content: Vec<_> = events
            .iter()
            .map(|ev| to_event_content_path(kind, ev, Some("Redacted"), ruma_events))
            .collect();

        quote! {
            #( #attrs )*
            #[derive(Clone, Debug, #serde::Serialize)]
            #[serde(untagged)]
            #[allow(clippy::large_enum_variant)]
            pub enum #redacted_ident {
                #(
                    #[doc = #event_type_str]
                    #variant_decls(#redacted_content),
                )*
                /// Content of a redacted event not defined by the Matrix specification.
                #[doc(hidden)]
                _Custom(#ruma_events::custom::RedactedCustomEventContent),
            }

            impl #ruma_events::RedactContent for #ident {
                type Redacted = #redacted_ident;

                /// Redacts `Self` given a `RoomVersionId`.
                fn redact(
                    self,
                    version: &#ruma_identifiers::RoomVersionId,
                ) -> #redacted_ident {
                    match self {
                        #(
                            #variant_arms(content) => {
                                #redaction_variants(
                                    #ruma_events::RedactContent::redact(content, version)
                                )
                            },
                        )*
                        Self::_Custom(content) => {
                            #redacted_ident::_Custom(
                                #ruma_events::RedactContent::redact(content, version)
                            )
                        },
                    }
                }
            }
        }
    } else {
        TokenStream::new()
    };

    quote! {
        #content_enum

        #event_content_impl

        #marker_trait_impl

        #redacted_content_enum
    }
}
/// Create a content enum from `EventEnumInput`.
Create a content enum from `EventEnumInput`.
Create a content enum from ` EventEnumInput ` .
fn expand_content_enum(
    kind: &EventKind,
    events: &[LitStr],
    attrs: &[Attribute],
    variants: &[EventEnumVariant],
    ruma_events: &TokenStream,
) -> TokenStream {
    let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers };
    let serde = quote! { #ruma_events::exports::serde };
    let serde_json = quote! { #ruma_events::exports::serde_json };
    let ident = kind.to_content_enum();
    let event_type_str = events;
    let content: Vec<_> =
        events.iter().map(|ev| to_event_content_path(kind, ev, None, ruma_events)).collect();
    let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>();
    let content_enum = quote! {
        #( #attrs )*
        #[derive(Clone, Debug, #serde::Serialize)]
        #[serde(untagged)]
        #[allow(clippy::large_enum_variant)]
        pub enum #ident {
            #(
                #[doc = #event_type_str]
                #variant_decls(#content),
            )*
            /// Content of an event not defined by the Matrix specification.
            #[doc(hidden)]
            _Custom(#ruma_events::custom::CustomEventContent),
        }
    };
    let variant_attrs = variants.iter().map(|v| {
        let attrs = &v.attrs;
        quote! { #(#attrs)* }
    });
    let variant_arms = variants.iter().map(|v| v.match_arm(quote!(Self))).collect::<Vec<_>>();
    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) -> &::std::primitive::str {
                match self {
                    #( #variant_arms(content) => content.event_type(), )*
                    Self::_Custom(content) => content.event_type(),
                }
            }
            fn from_parts(
                event_type: &::std::primitive::str,
                input: &#serde_json::value::RawValue,
            ) -> #serde_json::Result<Self> {
                match event_type {
                    #(
                        #variant_attrs #event_type_str => {
                            let content = #content::from_parts(event_type, input)?;
                            ::std::result::Result::Ok(#variant_ctors(content))
                        },
                    )*
                    ev_type => {
                        let content =
                            #ruma_events::custom::CustomEventContent::from_parts(ev_type, input)?;
                        ::std::result::Result::Ok(Self::_Custom(content))
                    },
                }
            }
        }
    };
    let marker_trait_impl = marker_trait(kind, ruma_events);
    let redacted_content_enum = if kind.is_state() || kind.is_message() {
        let redacted_ident = kind.to_redacted_content_enum();
        let redaction_variants = variants.iter().map(|v| v.ctor(&redacted_ident));
        let redacted_content: Vec<_> = events
            .iter()
            .map(|ev| to_event_content_path(kind, ev, Some("Redacted"), ruma_events))
            .collect();
        quote! {
            #( #attrs )*
            #[derive(Clone, Debug, #serde::Serialize)]
            #[serde(untagged)]
            #[allow(clippy::large_enum_variant)]
            pub enum #redacted_ident {
                #(
                    #[doc = #event_type_str]
                    #variant_decls(#redacted_content),
                )*
                /// Content of a redacted event not defined by the Matrix specification.
                #[doc(hidden)]
                _Custom(#ruma_events::custom::RedactedCustomEventContent),
            }
            impl #ruma_events::RedactContent for #ident {
                type Redacted = #redacted_ident;
                /// Redacts `Self` given a `RoomVersionId`.
                fn redact(
                    self,
                    version: &#ruma_identifiers::RoomVersionId,
                ) -> #redacted_ident {
                    match self {
                        #(
                            #variant_arms(content) => {
                                #redaction_variants(
                                    #ruma_events::RedactContent::redact(content, version)
                                )
                            },
                        )*
                        Self::_Custom(content) => {
                            #redacted_ident::_Custom(
                                #ruma_events::RedactContent::redact(content, version)
                            )
                        },
                    }
                }
            }
        }
    } else {
        TokenStream::new()
    };
    quote! {
        #content_enum
        #event_content_impl
        #marker_trait_impl
        #redacted_content_enum
    }
}
fn expand_content_enum ( kind : & EventKind , events : & [ LitStr ] , attrs : & [ Attribute ] , variants : & [ EventEnumVariant ] , ruma_events : & TokenStream , ) -> TokenStream { let ruma_identifiers = quote ! { ruma_events exports ruma_identifiers } ; let serde = quote ! { ruma_events exports serde } ; let serde_json = quote ! { ruma_events exports serde_json } ; let ident = kind . to_content_enum ( ) ; let event_type_str = events ; let content : Vec < _ > = events . iter ( ) . map ( | ev | to_event_content_path ( kind , ev , None , ruma_events ) ) . collect ( ) ; let variant_decls = variants . iter ( ) . map ( | v | v . decl ( ) ) . collect :: < Vec < _ > > ( ) ; let content_enum = quote ! { ( attrs ) [ derive ( Clone Debug serde Serialize ) ] [ serde ( untagged ) ] [ allow ( clippy large_enum_variant ) ] pub enum ident { ( [ doc event_type_str ] variant_decls ( content ) ) /// Content of an event not defined by the Matrix specification. [ doc ( hidden ) ] _Custom ( ruma_events custom CustomEventContent ) } } ; let variant_attrs = variants . iter ( ) . map ( | v | { let attrs = & v . attrs ; quote ! { ( attrs ) } } ) ; let variant_arms = variants . iter ( ) . map ( | v | v . match_arm ( quote ! ( Self ) ) ) . collect :: < Vec < _ > > ( ) ; 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 ) std primitive str { match self { ( variant_arms ( content ) content event_type ( ) ) Self Custom ( content ) content event_type ( ) } } fn from_parts ( event_type std primitive str input serde_json value RawValue ) serde_json Result Self { match event_type { ( variant_attrs event_type_str { let content content from_parts ( event_type input ) std result Result Ok ( variant_ctors ( content ) ) } ) ev_type { let content ruma_events custom CustomEventContent from_parts ( ev_type input ) std result Result Ok ( Self Custom ( content ) ) } } } } } ; let marker_trait_impl = marker_trait ( kind , ruma_events ) ; let redacted_content_enum = if kind . is_state ( ) || kind . is_message ( ) { let redacted_ident = kind . to_redacted_content_enum ( ) ; let redaction_variants = variants . iter ( ) . map ( | v | v . ctor ( & redacted_ident ) ) ; let redacted_content : Vec < _ > = events . iter ( ) . map ( | ev | to_event_content_path ( kind , ev , Some ( " " ) , ruma_events ) ) . collect ( ) ; quote ! { ( attrs ) [ derive ( Clone Debug serde Serialize ) ] [ serde ( untagged ) ] [ allow ( clippy large_enum_variant ) ] pub enum redacted_ident { ( [ doc event_type_str ] variant_decls ( redacted_content ) ) /// Content of a redacted event not defined by the Matrix specification. [ doc ( hidden ) ] _Custom ( ruma_events custom RedactedCustomEventContent ) } impl ruma_events RedactContent for ident { type Redacted redacted_ident /// Redacts `Self` given a `RoomVersionId`. fn redact ( self version ruma_identifiers RoomVersionId ) redacted_ident { match self { ( variant_arms ( content ) { redaction_variants ( ruma_events RedactContent redact ( content version ) ) } ) Self Custom ( content ) { redacted_ident Custom ( ruma_events RedactContent redact ( content version ) ) } } } } } } else { TokenStream :: new ( ) } ; quote ! { content_enum event_content_impl marker_trait_impl redacted_content_enum } }
Create a content enum from `EventEnumInput`.
Create a content enum from ` EventEnumInput ` .
kind
&EventKind
events
&[LitStr]
attrs
&[Attribute]
variants
&[EventEnumVariant]
ruma_events
&TokenStream