Skip to main content

zulip_api/message/
saved_snippet.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents details of the saved snippet.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct SavedSnippet {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    id: Option<u64>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    title: Option<String>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    content: Option<String>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    date_created: Option<u64>,
38}
39
40impl SavedSnippet {
41    /// Creates a new [SavedSnippet].
42    pub const fn new() -> Self {
43        Self {
44            id: None,
45            title: None,
46            content: None,
47            date_created: None,
48        }
49    }
50}
51
52field_access! {
53    SavedSnippet {
54        /// The unique ID of the saved snippet.
55        id: option { u64 },
56        /// The UNIX timestamp for when the saved snippet was created, in UTC seconds.
57        date_created: option { u64 },
58    }
59}
60
61field_access! {
62    SavedSnippet {
63        /// The title of the saved snippet.
64        title: option_cow_deref { str, String },
65        /// The content of the saved snippet in [Zulip-flavored Markdown](https://zulip.com/help/format-your-message-using-markdown) format.
66        ///
67        /// Clients should insert this content into a message when using a saved snippet.
68        content: option_cow_deref { str, String },
69    }
70}
71
72impl_default!(SavedSnippet);
73impl_display!(SavedSnippet);