Turn long matches! into is_redacted EventKindVariation method
This commit is contained in:
parent
a39c0106d4
commit
2e1e63671d
@ -43,12 +43,7 @@ pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
let name = field.ident.as_ref().unwrap();
|
let name = field.ident.as_ref().unwrap();
|
||||||
if name == "content" && matches!(
|
if name == "content" && var.is_redacted() {
|
||||||
var,
|
|
||||||
EventKindVariation::Redacted
|
|
||||||
| EventKindVariation::RedactedSync
|
|
||||||
| EventKindVariation::RedactedStripped
|
|
||||||
) {
|
|
||||||
quote! {
|
quote! {
|
||||||
if ::ruma_events::RedactedEventContent::has_serialize_fields(&self.content) {
|
if ::ruma_events::RedactedEventContent::has_serialize_fields(&self.content) {
|
||||||
state.serialize_field("content", &self.content)?;
|
state.serialize_field("content", &self.content)?;
|
||||||
@ -161,12 +156,7 @@ fn expand_deserialize_event(
|
|||||||
.map(|field| {
|
.map(|field| {
|
||||||
let name = field.ident.as_ref().unwrap();
|
let name = field.ident.as_ref().unwrap();
|
||||||
if name == "content" {
|
if name == "content" {
|
||||||
if is_generic && matches!(
|
if is_generic && var.is_redacted() {
|
||||||
var,
|
|
||||||
EventKindVariation::Redacted
|
|
||||||
| EventKindVariation::RedactedSync
|
|
||||||
| EventKindVariation::RedactedStripped
|
|
||||||
) {
|
|
||||||
quote! {
|
quote! {
|
||||||
let content = match C::has_deserialize_fields() {
|
let content = match C::has_deserialize_fields() {
|
||||||
::ruma_events::HasDeserializeFields::False => {
|
::ruma_events::HasDeserializeFields::False => {
|
||||||
|
@ -25,6 +25,12 @@ pub enum EventKindVariation {
|
|||||||
ManuallyImpled,
|
ManuallyImpled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EventKindVariation {
|
||||||
|
pub fn is_redacted(&self) -> bool {
|
||||||
|
matches!(self, Self::Redacted | Self::RedactedSync | Self::RedactedStripped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the variants of this enum change `to_event_path` needs to be updated as well.
|
// If the variants of this enum change `to_event_path` needs to be updated as well.
|
||||||
pub enum EventKind {
|
pub enum EventKind {
|
||||||
Basic(Ident),
|
Basic(Ident),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user