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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use serde::{Deserialize, Serialize};
use crate::{field_access, impl_default, impl_display};
/// Represents a user's personal configuration for a specific navigation view.
///
/// Displayed most visibly at the top of the web application's left sidebar.
///
/// Navigation views can be either an override to the default behavior of a built-in view, or a custom view.
///
/// **Changes**: New in Zulip 11.0 (feature level 390).
///
/// 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 NavigationView {
fragment: String,
is_pinned: bool,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
}
field_access! {
NavigationView {
/// A unique identifier for the view, used to determine navigation behavior when clicked.
///
/// Clients should use this value to navigate to the corresponding URL hash.
fragment: cow { str },
}
}
field_access! {
NavigationView {
/// Determines whether the view appears directly in the sidebar or is hidden in the \"More Views\" menu.
///
/// - `true`: Pinned and visible in the sidebar.
/// - `false`: Hidden and accessible via the \"More Views\" menu.
is_pinned: bool,
}
}
field_access! {
NavigationView {
/// The user-facing name for custom navigation views.
///
/// Omit this field for built-in views.
name: option_cow_deref { str, String },
}
}
impl NavigationView {
/// Creates a new [NavigationView].
pub const fn new() -> Self {
Self {
fragment: String::new(),
is_pinned: false,
name: None,
}
}
}
impl_default!(NavigationView);
impl_display!(NavigationView);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_navigation_view() {
let fragment = "test fragment";
let is_pinned = true;
let name = "test name";
let view = NavigationView::new()
.with_fragment(fragment)
.with_is_pinned(is_pinned)
.with_name(name);
let view_json = view.to_string();
assert_eq!(serde_json::to_string(&view).unwrap(), view_json);
assert_eq!(
serde_json::from_str::<NavigationView>(&view_json).unwrap(),
view
);
assert_eq!(view.fragment(), fragment);
assert_eq!(view.is_pinned(), is_pinned);
assert_eq!(view.name(), Some(name));
}
}