vtx-sdk 0.1.14

Official SDK for developing VTX plugins using Rust and WebAssembly.
Documentation
//! Host-side event types and helpers.

use crate::bindings::vtx::api::vtx_events::{EventContext, VtxEvent};
use crate::error::{VtxError, VtxResult};
use serde::de::DeserializeOwned;

pub type PluginEvent = VtxEvent;
pub type PluginEventContext = EventContext;

pub trait VtxEventExt {
    /// Deserializes the `payload` (JSON string) into the target type.
    fn payload_json<T: DeserializeOwned>(&self) -> VtxResult<T>;
}

impl VtxEventExt for VtxEvent {
    fn payload_json<T: DeserializeOwned>(&self) -> VtxResult<T> {
        serde_json::from_str(&self.payload).map_err(|e| VtxError::SerializationError(e.to_string()))
    }
}