twilight_model/channel/message/
role_subscription_data.rs

1use crate::id::{marker::RoleSubscriptionSkuMarker, Id};
2use serde::{Deserialize, Serialize};
3
4/// Information about a role subscription that created a [`Message`].
5///
6/// [`Message`]: super::Message
7#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
8pub struct RoleSubscriptionData {
9    /// Whether this notification is for a renewal rather than a new purchase.
10    pub is_renewal: bool,
11    /// ID of the SKU and listing that the user is subscribed to.
12    pub role_subscription_listing_id: Id<RoleSubscriptionSkuMarker>,
13    /// Name of the tier that the user is subscribed to.
14    pub tier_name: String,
15    /// Cumulative number of months that the user has been subscribed for.
16    pub total_months_subscribed: u16,
17}
18
19#[cfg(test)]
20mod tests {
21    use super::RoleSubscriptionData;
22    use crate::id::Id;
23    use serde::{Deserialize, Serialize};
24    use serde_test::Token;
25    use static_assertions::{assert_fields, assert_impl_all};
26    use std::{fmt::Debug, hash::Hash};
27
28    assert_fields!(
29        RoleSubscriptionData: is_renewal,
30        role_subscription_listing_id,
31        tier_name,
32        total_months_subscribed
33    );
34    assert_impl_all!(
35        RoleSubscriptionData: Clone,
36        Debug,
37        Deserialize<'static>,
38        Eq,
39        Hash,
40        PartialEq,
41        Send,
42        Serialize,
43        Sync
44    );
45
46    #[test]
47    fn serde() {
48        let value = RoleSubscriptionData {
49            is_renewal: true,
50            role_subscription_listing_id: Id::new(1),
51            tier_name: "sparkle".to_owned(),
52            total_months_subscribed: 4,
53        };
54
55        serde_test::assert_tokens(
56            &value,
57            &[
58                Token::Struct {
59                    name: "RoleSubscriptionData",
60                    len: 4,
61                },
62                Token::Str("is_renewal"),
63                Token::Bool(true),
64                Token::Str("role_subscription_listing_id"),
65                Token::NewtypeStruct { name: "Id" },
66                Token::Str("1"),
67                Token::Str("tier_name"),
68                Token::Str("sparkle"),
69                Token::Str("total_months_subscribed"),
70                Token::U16(4),
71                Token::StructEnd,
72            ],
73        );
74    }
75}