pub const OPERATOR_ID_SYNTAX_VERSION: u16 = 1;
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(transparent)]
pub struct OperatorId(String);
impl OperatorId {
pub fn new(operator_id: impl Into<String>) -> Self {
Self(operator_id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub const fn syntax_version() -> u16 {
OPERATOR_ID_SYNTAX_VERSION
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn given_operator_id_when_serialized_then_version_one_is_a_transparent_string() {
let operator_id = OperatorId::new("operator.example");
let encoded = serde_json::to_string(&operator_id).unwrap();
let decoded: OperatorId = serde_json::from_str(&encoded).unwrap();
assert_eq!(OperatorId::syntax_version(), 1);
assert_eq!(encoded, "\"operator.example\"");
assert_eq!(decoded, operator_id);
}
}