use serde::{Deserialize, Serialize};
use crate::response::BaseResponse;
use crate::{field_access, impl_default, impl_display, impl_response};
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Response {
#[serde(flatten)]
base: BaseResponse,
messages: Option<Vec<u64>>,
ignored_because_not_subscribed_channels: Option<Vec<u64>>,
}
impl Response {
pub const fn new() -> Self {
Self {
base: BaseResponse::new(),
messages: None,
ignored_because_not_subscribed_channels: None,
}
}
}
field_access! {
Response {
messages: option_cow_deref { [u64], Vec<u64> },
ignored_because_not_subscribed_channels: option_cow_deref { [u64], Vec<u64> },
}
}
impl_default!(Response);
impl_display!(Response);
impl_response!(Response, base);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_response() {
let messages = [1u64];
let ignored_because_not_subscribed_channels = [2u64];
let response = Response::new()
.with_messages(messages.as_ref())
.with_ignored_because_not_subscribed_channels(
ignored_because_not_subscribed_channels.as_ref(),
);
let response_json = response.to_string();
assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
assert_eq!(
serde_json::from_str::<Response>(&response_json).unwrap(),
response
);
assert_eq!(response.messages(), Some(messages.as_ref()));
assert_eq!(
response.ignored_because_not_subscribed_channels(),
Some(ignored_because_not_subscribed_channels.as_ref())
);
}
}