pub mod simulation {
use phoxal_bus::{
ApiVersion, EndpointDescriptor, EndpointKind, EventContract, Publish,
StreamDeliveryContract, Subscribe, Topic, WorldClockContract,
};
use serde::{Deserialize, Serialize};
#[doc(hidden)]
pub enum Api {}
impl ApiVersion for Api {
const ID: &'static str = "runtime";
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Clock {
pub step: u64,
}
#[doc(hidden)]
pub struct ClockEndpoint;
impl EndpointDescriptor for ClockEndpoint {
type Api = Api;
type Payload = Clock;
const NAME: &'static str = "runtime::simulation::Clock";
const VERSION: &'static str = "runtime";
const CONTRACT: &'static str = "simulation::Clock";
const TOPIC: &'static str = "runtime/simulation/clock";
const KIND: EndpointKind = EndpointKind::Event;
}
impl EventContract for ClockEndpoint {}
impl StreamDeliveryContract for ClockEndpoint {}
impl WorldClockContract for ClockEndpoint {}
#[doc(hidden)]
pub fn owner_topic() -> Topic<Publish<ClockEndpoint>> {
Topic::new_static(<ClockEndpoint as EndpointDescriptor>::TOPIC)
}
#[doc(hidden)]
pub fn client_topic() -> Topic<Subscribe<ClockEndpoint>> {
Topic::new_static(<ClockEndpoint as EndpointDescriptor>::TOPIC)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn clock_hand_is_runtime_owned_and_ordered() {
assert_eq!(ClockEndpoint::VERSION, "runtime");
assert_eq!(ClockEndpoint::TOPIC, "runtime/simulation/clock");
assert_eq!(ClockEndpoint::KIND, EndpointKind::Event);
assert_eq!(owner_topic().key(), client_topic().key());
assert_eq!(
serde_json::to_value(Clock { step: 7 }).unwrap(),
serde_json::json!({"step": 7})
);
}
}
}