Skip to main content

zulip_api/message/
topics_policy.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{impl_default, impl_display};
4
5/// Represents whether named topics and the empty topic are enabled in a channel.
6///
7/// - `\"inherit\"`: Messages can be sent to named topics in this channel, and the organization-level `realm_topics_policy` is used for whether messages can be sent to the empty topic in this   channel.
8/// - `\"allow_empty_topic\"`: Messages can be sent to both named topics and the empty topic in this channel.
9/// - `\"disable_empty_topic\"`: Messages can be sent to named topics in this channel, but the empty topic is disabled.
10/// - `\"empty_topic_only\"`: Messages can be sent to the empty topic in this channel, but named topics are disabled.
11///
12/// The `\"empty_topic_only\"` policy can only be set if all existing messages in the channel are already in the empty topic.  When creating a new channel, if the `topics_policy` is not specified, the `\"inherit\"` option will be set.
13///
14/// **Changes**: In Zulip 11.0 (feature level 404), the `\"empty_topic_only\"` option was added.  New in Zulip 11.0 (feature level 392).  [realm-topics-policy]: /help/require-topics#set-the-default-general-chat-topic-configuration
15///
16/// Modified from `openapi-generator-cli` output:
17///
18/// ```shell,no_build,no_run
19/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
20/// ```
21///
22/// ```text
23/// /*
24/// * Zulip REST API
25/// *
26/// * Powerful open source group chat
27/// *
28/// * The version of the OpenAPI document: 1.0.0
29/// *
30/// * Generated by: https://openapi-generator.tech
31/// */
32/// ```
33///
34/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
35///
36/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
37#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
38#[serde(rename_all = "snake_case")]
39pub enum TopicsPolicy {
40    Inherit,
41    AllowEmptyTopic,
42    DisableEmptyTopic,
43    EmptyTopicOnly,
44}
45
46impl TopicsPolicy {
47    /// Creates a new [TopicsPolicy].
48    pub const fn new() -> Self {
49        Self::Inherit
50    }
51
52    /// Gets the [TopicsPolicy] string representation.
53    pub const fn as_str(&self) -> &'static str {
54        match self {
55            Self::Inherit => "inherit",
56            Self::AllowEmptyTopic => "allow_empty_topic",
57            Self::DisableEmptyTopic => "disable_empty_topic",
58            Self::EmptyTopicOnly => "empty_topic_only",
59        }
60    }
61}
62
63impl_default!(TopicsPolicy);
64impl_display!(TopicsPolicy);