matrix_sdk/sliding_sync/list/
frozen.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use serde::{Deserialize, Serialize};

use super::SlidingSyncList;

#[derive(Debug, Serialize, Deserialize)]
pub struct FrozenSlidingSyncList {
    #[serde(default, rename = "rooms_count", skip_serializing_if = "Option::is_none")]
    pub maximum_number_of_rooms: Option<u32>,
}

impl FrozenSlidingSyncList {
    pub(in super::super) fn freeze(source_list: &SlidingSyncList) -> Self {
        FrozenSlidingSyncList { maximum_number_of_rooms: source_list.maximum_number_of_rooms() }
    }
}

#[cfg(test)]
mod tests {
    use serde_json::json;

    use super::FrozenSlidingSyncList;

    #[test]
    fn test_frozen_sliding_sync_list_serialization() {
        assert_eq!(
            serde_json::to_value(&FrozenSlidingSyncList { maximum_number_of_rooms: Some(42) })
                .unwrap(),
            json!({
                "rooms_count": 42,
            })
        );
    }
}