events: Refactor macro code
Use Option::zip which was not possible with the previous MSRV.
This commit is contained in:
parent
e622803679
commit
de737f30e7
@ -583,14 +583,7 @@ fn expand_redacted_enum(
|
|||||||
|
|
||||||
if let EventKind::State | EventKind::Message = kind {
|
if let EventKind::State | EventKind::Message = kind {
|
||||||
let ident = format_ident!("AnyPossiblyRedacted{}", kind.to_event_ident(var)?);
|
let ident = format_ident!("AnyPossiblyRedacted{}", kind.to_event_ident(var)?);
|
||||||
|
let (regular_enum_ident, redacted_enum_ident) = inner_enum_idents(kind, var)?;
|
||||||
// FIXME: Use Option::zip once MSRV >= 1.46
|
|
||||||
let (regular_enum_ident, redacted_enum_ident) = match inner_enum_idents(kind, var) {
|
|
||||||
(Some(regular_enum_ident), Some(redacted_enum_ident)) => {
|
|
||||||
(regular_enum_ident, redacted_enum_ident)
|
|
||||||
}
|
|
||||||
_ => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
/// An enum that holds either regular un-redacted events or redacted events.
|
/// An enum that holds either regular un-redacted events or redacted events.
|
||||||
@ -628,7 +621,7 @@ fn expand_redacted_enum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_event_idents(kind: &EventKind, var: &EventKindVariation) -> Option<(Ident, Ident)> {
|
fn generate_event_idents(kind: &EventKind, var: &EventKindVariation) -> Option<(Ident, Ident)> {
|
||||||
Some((kind.to_event_ident(var)?, kind.to_event_enum_ident(var)?))
|
kind.to_event_ident(var).zip(kind.to_event_enum_ident(var))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_redacted_fields(
|
fn generate_redacted_fields(
|
||||||
@ -800,22 +793,22 @@ fn accessor_methods(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inner_enum_idents(kind: &EventKind, var: &EventKindVariation) -> (Option<Ident>, Option<Ident>) {
|
fn inner_enum_idents(kind: &EventKind, var: &EventKindVariation) -> Option<(Ident, Ident)> {
|
||||||
match var {
|
Some(match var {
|
||||||
EventKindVariation::Full => {
|
EventKindVariation::Full => (
|
||||||
(kind.to_event_enum_ident(var), kind.to_event_enum_ident(&EventKindVariation::Redacted))
|
kind.to_event_enum_ident(var)?,
|
||||||
}
|
kind.to_event_enum_ident(&EventKindVariation::Redacted)?,
|
||||||
|
),
|
||||||
EventKindVariation::Sync => (
|
EventKindVariation::Sync => (
|
||||||
kind.to_event_enum_ident(var),
|
kind.to_event_enum_ident(var)?,
|
||||||
kind.to_event_enum_ident(&EventKindVariation::RedactedSync),
|
kind.to_event_enum_ident(&EventKindVariation::RedactedSync)?,
|
||||||
),
|
),
|
||||||
EventKindVariation::Stripped => (
|
EventKindVariation::Stripped => (
|
||||||
kind.to_event_enum_ident(var),
|
kind.to_event_enum_ident(var)?,
|
||||||
kind.to_event_enum_ident(&EventKindVariation::RedactedStripped),
|
kind.to_event_enum_ident(&EventKindVariation::RedactedStripped)?,
|
||||||
),
|
),
|
||||||
EventKindVariation::Initial => (kind.to_event_enum_ident(var), None),
|
_ => return None,
|
||||||
_ => (None, None),
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Redacted events do NOT generate `content` or `prev_content` methods like
|
/// Redacted events do NOT generate `content` or `prev_content` methods like
|
||||||
|
Loading…
x
Reference in New Issue
Block a user