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 user ID and timestamp of a muted user.
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MutedUser {
    #[serde(skip_serializing_if = "Option::is_none")]
    id: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    timestamp: Option<u64>,
}

impl MutedUser {
    /// Creates a new [MutedUser].
    pub const fn new() -> Self {
        Self {
            id: None,
            timestamp: None,
        }
    }
}

field_access! {
    MutedUser {
        /// The ID of the muted user.
        id: option { u64 },
        /// An integer UNIX timestamp representing when the user was muted.
        timestamp: option { u64 },
    }
}

impl_default!(MutedUser);
impl_display!(MutedUser);

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

    #[test]
    fn test_user() {
        let id = 1;
        let timestamp = 2;

        let user = MutedUser::new().with_id(id).with_timestamp(timestamp);
        let user_json = user.to_string();

        assert_eq!(serde_json::to_string(&user).unwrap(), user_json);
        assert_eq!(serde_json::from_str::<MutedUser>(&user_json).unwrap(), user);

        assert_eq!(user.id(), Some(id));
        assert_eq!(user.timestamp(), Some(timestamp));
    }
}