use serde::Deserialize;
use serde::Serialize;
#[derive(Debug, Clone, Default, Serialize, Deserialize, Hash, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SimpleSubscriptionData {
topic: String,
expression_type: String,
expression: String,
version: u64,
}
impl SimpleSubscriptionData {
pub fn new(topic: String, expression_type: String, expression: String, version: u64) -> Self {
SimpleSubscriptionData {
topic,
expression_type,
expression,
version,
}
}
pub fn topic(&self) -> &str {
&self.topic
}
pub fn expression_type(&self) -> &str {
&self.expression_type
}
pub fn expression(&self) -> &str {
&self.expression
}
pub fn version(&self) -> u64 {
self.version
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn simple_subscription_data_default() {
let data = SimpleSubscriptionData::default();
assert_eq!(data.topic(), "");
assert_eq!(data.expression_type(), "");
assert_eq!(data.expression(), "");
assert_eq!(data.version(), 0);
}
#[test]
fn simple_subscription_data_new_and_getters() {
let data = SimpleSubscriptionData::new("topic".to_string(), "TAG".to_string(), "*".to_string(), 123);
assert_eq!(data.topic(), "topic");
assert_eq!(data.expression_type(), "TAG");
assert_eq!(data.expression(), "*");
assert_eq!(data.version(), 123);
}
}