zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde::{Deserialize, Serialize};

use crate::response::BaseResponse;
use crate::{field_access, impl_default, impl_display, impl_response};

/// Represents the response for the `Mark All as Read` Zulip API endpoint.
///
/// See [mark-all-as-read](https://zulip.com/api/mark-all-as-read) for details.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Response {
    #[serde(flatten)]
    base: BaseResponse,
    complete: Option<bool>,
}

impl Response {
    /// Creates a new [Response].
    pub const fn new() -> Self {
        Self {
            base: BaseResponse::new(),
            complete: None,
        }
    }
}

field_access! {
    Response {
        /// Whether all unread messages were marked as read.
        ///
        /// Will be `false` if the request successfully marked
        /// some, but not all, messages as read.
        complete: option { bool },
    }
}

impl_default!(Response);
impl_display!(Response);
impl_response!(Response, base);

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_response() {
        let complete = true;

        let response = Response::new().with_complete(complete);
        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.complete(), Some(complete));
    }
}