zulip-api 0.0.8

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

use crate::{field_access, impl_default, impl_display};

/// Represents the response for the `Mark Stream as Read` Zulip API endpoint.
///
/// See [mark-stream-as-read](https://zulip.com/api/mark-stream-as-read) for details.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Request {
    stream_id: u64,
}

impl Request {
    /// Creates a new [Request].
    pub const fn new() -> Self {
        Self { stream_id: 0 }
    }
}

field_access! {
    Request {
        /// The ID of the channel to access.
        stream_id: u64,
    }
}

impl_default!(Request);
impl_display!(Request);

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

    #[test]
    fn test_request() {
        let stream_id = 1;

        let request = Request::new().with_stream_id(stream_id);
        let request_json = request.to_string();

        assert_eq!(serde_json::to_string(&request).unwrap(), request_json);
        assert_eq!(
            serde_json::from_str::<Request>(&request_json).unwrap(),
            request
        );

        assert_eq!(request.stream_id(), stream_id);
    }
}