use std::fmt::Debug;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::envelope::{Labels, NoDimensions, Source};
use crate::filter::LabelMatch;
pub trait Wire:
Serialize + DeserializeOwned + JsonSchema + Clone + PartialEq + Debug + Send + Sync + 'static
{
}
impl<T> Wire for T where
T: Serialize
+ DeserializeOwned
+ JsonSchema
+ Clone
+ PartialEq
+ Debug
+ Send
+ Sync
+ 'static
{
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
pub enum Admits {
Text,
Integer,
Word,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, JsonSchema)]
pub struct Reserved {
pub key: &'static str,
pub admits: Admits,
}
impl Reserved {
#[must_use]
pub const fn text(key: &'static str) -> Self {
Self {
key,
admits: Admits::Text,
}
}
#[must_use]
pub const fn integer(key: &'static str) -> Self {
Self {
key,
admits: Admits::Integer,
}
}
#[must_use]
pub const fn word(key: &'static str) -> Self {
Self {
key,
admits: Admits::Word,
}
}
}
pub trait Vocabulary: Debug + Clone + PartialEq + Send + Sync + 'static {
type Source: Wire + std::fmt::Display;
type Dimensions: Wire + Default;
type Labels: Wire + Default;
type Fields: Wire + Default;
const NAME: &'static str;
const RESERVED: &'static [Reserved];
const DIMENSIONS: &'static [Reserved];
const DEFAULT_SOURCE: &'static str;
fn write_version(source: &Self::Source) -> u32;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Open;
impl Vocabulary for Open {
type Source = Source;
type Dimensions = NoDimensions;
type Labels = Labels;
type Fields = LabelMatch;
const NAME: &'static str = "open";
const RESERVED: &'static [Reserved] = &[];
const DIMENSIONS: &'static [Reserved] = &[];
const DEFAULT_SOURCE: &'static str = "onemessagebus";
fn write_version(_: &Self::Source) -> u32 {
1
}
}