falco_plugin/event/
mod.rs

1//! # Event-related types
2//!
3//! This module reexports the whole of [`falco_event`] (except the macros), as well as exports
4//! the event types defined by this crate (the minimal subset of the full Falco schema)
5
6mod async_event;
7mod event_input;
8mod json;
9mod plugin_event;
10
11pub use async_event::AsyncEvent;
12pub use event_input::EventInput;
13use falco_event::fields::{FromBytes, ToBytes};
14pub use falco_event::{events, fields};
15pub use json::JsonPayload;
16pub use plugin_event::PluginEvent;
17use std::fmt::Debug;
18
19/// Provide an event source name for an event type
20///
21/// This is required to use that type as an event payload
22pub trait EventSource {
23    /// Source name
24    ///
25    /// `syscall` for system call events, an arbitrary string (matching the one in the source plugin
26    /// implementation) for custom plugin/async events
27    const SOURCE: Option<&'static str>;
28}
29
30impl EventSource for &[u8] {
31    const SOURCE: Option<&'static str> = None;
32}
33
34/// A generic enum for custom plugin/async event payloads
35///
36/// Type parameters:
37/// - `P` specifies the payload of the `Plugin` variant
38/// - `A` specifies the payload of the `Async` variant
39#[derive(falco_event::AnyEvent)]
40#[allow(missing_docs)]
41pub enum AnyPluginEvent<'a, P, A>
42where
43    for<'b> P: EventSource + ToBytes + FromBytes<'b> + Debug,
44    A: EventSource + ToBytes + FromBytes<'a> + Debug,
45{
46    Plugin(PluginEvent<P>),
47    Async(AsyncEvent<'a, A>),
48}