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,
#[serde(skip_serializing_if = "Option::is_none")]
user_ids: Option<Vec<u64>>,
}
impl Response {
pub const fn new() -> Self {
Self {
base: BaseResponse::new(),
user_ids: None,
}
}
}
field_access! {
Response {
user_ids: 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 user_ids = [1];
let response = Response::new().with_user_ids(user_ids.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.user_ids(), Some(user_ids.as_ref()));
}
}