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()
|
||||
.map(|field| {
|
||||
let name = field.ident.as_ref().unwrap();
|
||||
if name == "content" && matches!(
|
||||
var,
|
||||
EventKindVariation::Redacted
|
||||
| EventKindVariation::RedactedSync
|
||||
| EventKindVariation::RedactedStripped
|
||||
) {
|
||||
if name == "content" && var.is_redacted() {
|
||||
quote! {
|
||||
if ::ruma_events::RedactedEventContent::has_serialize_fields(&self.content) {
|
||||
state.serialize_field("content", &self.content)?;
|
||||
@ -161,12 +156,7 @@ fn expand_deserialize_event(
|
||||
.map(|field| {
|
||||
let name = field.ident.as_ref().unwrap();
|
||||
if name == "content" {
|
||||
if is_generic && matches!(
|
||||
var,
|
||||
EventKindVariation::Redacted
|
||||
| EventKindVariation::RedactedSync
|
||||
| EventKindVariation::RedactedStripped
|
||||
) {
|
||||
if is_generic && var.is_redacted() {
|
||||
quote! {
|
||||
let content = match C::has_deserialize_fields() {
|
||||
::ruma_events::HasDeserializeFields::False => {
|
||||
|
@ -25,6 +25,12 @@ pub enum EventKindVariation {
|
||||
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.
|
||||
pub enum EventKind {
|
||||
Basic(Ident),
|
||||
|
Loading…
x
Reference in New Issue
Block a user