Macro trillium_channels::event
source ยท macro_rules! event { ($topic:expr, $event:expr) => { ... }; ($topic:expr, $event:expr, $($json:tt)+) => { ... }; }
Expand description
This macro provides a convenient constructor for a
ChannelEvent
. It is called with a topic, an event, and an optional
inline json payload.
let event = trillium_channels::event!("some:topic", "some:event");
assert_eq!(event.topic(), "some:topic");
assert_eq!(event.event(), "some:event");
assert_eq!(serde_json::to_string(event.payload()).unwrap(), "{}");
let event = trillium_channels::event!("some:topic", "some:event", { "payload": ["any", "json"] });
assert_eq!(event.topic(), "some:topic");
assert_eq!(event.event(), "some:event");
assert_eq!(serde_json::to_string(event.payload()).unwrap(), r#"{"payload":["any","json"]}"#);