Derive Macro AnyEvent

Source
#[derive(AnyEvent)]
{
    // Attributes available to this derive:
    #[falco_event_crate]
}
Expand description

Use this macro to define an enum like falco_event::events::types::AnyEvent, that is usable wherever another event type is. For example,

use std::ffi::CStr;
use anyhow::{anyhow, Context};
use falco_event::events::PayloadFromBytesError;

#[derive(Default, Debug, falco_event::EventPayload)]
#[event_payload(source = Some("syscall"), code = 322, length_type = u32)]
pub struct MyPluginEvent<'a> {
    pub plugin_id: u32,
    pub data: &'a [u8],
}

#[derive(Default, Debug, falco_event::EventPayload)]
#[event_payload(source = Some("syscall"), code = 322, length_type = u32)]
pub struct MyAsyncEvent<'a> {
    pub plugin_id: u32,
    pub name: &'a [u8],
    pub data: &'a [u8],
}

#[derive(falco_event_derive::AnyEvent)]
pub enum AnyPluginEvent<'a> {
    AsyncEvent(MyAsyncEvent<'a>),
    PluginEvent(MyPluginEvent<'a>),
}

If the falco_event crate is available under a different path, provide its name in the falco_event_crate attribute:

#[derive(falco_event_alt::AnyEvent)]
#[falco_event_crate(falco_event_alt)]
pub enum AnyPluginEvent<'a> {
    AsyncEvent(MyAsyncEvent<'a>),
    PluginEvent(MyPluginEvent<'a>),
}

§Requirements

To use this macro on an enum, all its variants need to have exactly one unnamed field, which implements the following traits:

One way to fullfil these requirements is to use the EventPayload macro on the variant field’s type.

§Derived traits

This macro implements the following traits on the enum type: