Skip to main content

zulip_api/message/mark_stream_as_read/
request.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents the response for the `Mark Stream as Read` Zulip API endpoint.
6///
7/// See [mark-stream-as-read](https://zulip.com/api/mark-stream-as-read) for details.
8#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
9pub struct Request {
10    stream_id: u64,
11}
12
13impl Request {
14    /// Creates a new [Request].
15    pub const fn new() -> Self {
16        Self { stream_id: 0 }
17    }
18}
19
20field_access! {
21    Request {
22        /// The ID of the channel to access.
23        stream_id: u64,
24    }
25}
26
27impl_default!(Request);
28impl_display!(Request);
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_request() {
36        let stream_id = 1;
37
38        let request = Request::new().with_stream_id(stream_id);
39        let request_json = request.to_string();
40
41        assert_eq!(serde_json::to_string(&request).unwrap(), request_json);
42        assert_eq!(
43            serde_json::from_str::<Request>(&request_json).unwrap(),
44            request
45        );
46
47        assert_eq!(request.stream_id(), stream_id);
48    }
49}