json_rules_engine_fork/event/
mod.rs

1use crate::error::Error;
2
3use async_trait::async_trait;
4use erased_serde::Serialize as ErasedSerialize;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use std::collections::HashMap;
9
10#[cfg(feature = "email")]
11pub mod email_notification;
12#[cfg(feature = "callback")]
13pub mod post_callback;
14
15#[derive(Clone, Debug, Serialize, Deserialize)]
16pub struct CoalescenceEvent {
17    pub(crate) coalescence: Option<u64>,
18    pub(crate) coalescence_group: Option<String>,
19    #[serde(flatten)]
20    pub(crate) event: Event,
21}
22
23#[derive(Clone, Debug, Serialize, Deserialize)]
24pub struct Event {
25    #[serde(rename = "type")]
26    pub ty: String,
27    pub params: HashMap<String, Value>,
28}
29
30#[async_trait]
31pub trait EventTrait {
32    fn new() -> Self
33    where
34        Self: Sized;
35
36    fn get_type(&self) -> &str;
37
38    fn validate(&self, params: &HashMap<String, Value>) -> Result<(), String>;
39
40    async fn trigger(
41        &mut self,
42        params: &HashMap<String, Value>,
43        facts: &(dyn ErasedSerialize + Sync),
44    ) -> Result<(), Error>;
45}