Skip to main content

zulip_api/message/
operation.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{impl_default, impl_display};
4
5/// Represents whether to add or remove a flag.
6#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
7#[serde(rename_all = "snake_case")]
8pub enum Operation {
9    Add,
10    Remove,
11}
12
13impl Operation {
14    /// Represent the string value for the `add` operation.
15    pub const ADD: &str = "add";
16    /// Represent the string value for the `remove` operation.
17    pub const REMOVE: &str = "remove";
18
19    /// Creates a new [Operation].
20    pub const fn new() -> Self {
21        Self::Add
22    }
23
24    /// Gets the string representation of the [Operation].
25    pub const fn as_str(&self) -> &'static str {
26        match self {
27            Self::Add => Self::ADD,
28            Self::Remove => Self::REMOVE,
29        }
30    }
31}
32
33impl_default!(Operation);
34impl_display!(Operation: str);