vtx_sdk/modules/event/
types.rs

1//! Host-side event types and helpers.
2
3use crate::bindings::vtx::api::vtx_events::{EventContext, VtxEvent};
4use crate::error::{VtxError, VtxResult};
5use serde::de::DeserializeOwned;
6
7pub type PluginEvent = VtxEvent;
8pub type PluginEventContext = EventContext;
9
10pub trait VtxEventExt {
11    /// Deserializes the `payload` (JSON string) into the target type.
12    fn payload_json<T: DeserializeOwned>(&self) -> VtxResult<T>;
13}
14
15impl VtxEventExt for VtxEvent {
16    fn payload_json<T: DeserializeOwned>(&self) -> VtxResult<T> {
17        serde_json::from_str(&self.payload).map_err(|e| VtxError::SerializationError(e.to_string()))
18    }
19}