Turn long matches! into is_redacted EventKindVariation method

This commit is contained in:
Devin R 2020-07-22 18:57:52 -04:00 committed by Jonas Platte
parent a39c0106d4
commit 2e1e63671d
2 changed files with 8 additions and 12 deletions

View File

@ -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 => {

View File

@ -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),