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
use crate::{impl_default, std::fmt};

use super::{Method, CLOSE_BRACE, OPEN_BRACE};

/// Represents a [Disable](crate::ResponseDisable::Disable) event.
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DisableEvent;

impl DisableEvent {
    /// Creates a new [DisableEvent].
    pub const fn new() -> Self {
        Self {}
    }

    /// Gets the [Method] for the [DisableEvent].
    pub const fn method() -> Method {
        Method::Disable
    }

    /// Converts the [DisableEvent] to a string.
    pub const fn to_str(&self) -> &'static str {
        Self::method().to_str()
    }

    /// Gets the length of the event in a [PollResponse](crate::PollResponse).
    pub const fn len() -> usize {
        1
    }
}

impl From<&DisableEvent> for &'static str {
    fn from(val: &DisableEvent) -> Self {
        val.to_str()
    }
}

impl From<DisableEvent> for &'static str {
    fn from(val: DisableEvent) -> Self {
        (&val).into()
    }
}

impl fmt::Display for DisableEvent {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{OPEN_BRACE}\"{}\"{CLOSE_BRACE}", self.to_str())
    }
}

impl_default!(DisableEvent);