scylla_cql/frame/
server_event_type.rs

1//! This module defines the `EventType` enum, which represents different types of CQL events.
2// TODO(2.0): Move this to a more appropriate location in the crate structure.
3
4use std::fmt;
5use std::str::FromStr;
6
7use super::frame_errors::CqlEventParseError;
8
9/// Represents the type of a CQL event.
10// Check triggers because all variants end with "Change".
11// TODO(2.0): Remove the "Change" postfix from variants.
12#[expect(clippy::enum_variant_names)]
13pub enum EventType {
14    /// Represents a change in the cluster topology, such as node addition or removal.
15    TopologyChange,
16    /// Represents a change in the status of a node, such as up or down.
17    StatusChange,
18    /// Represents a change in the schema, such as table creation or modification.
19    SchemaChange,
20}
21
22impl fmt::Display for EventType {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        let s = match &self {
25            Self::TopologyChange => "TOPOLOGY_CHANGE",
26            Self::StatusChange => "STATUS_CHANGE",
27            Self::SchemaChange => "SCHEMA_CHANGE",
28        };
29
30        write!(f, "{s}")
31    }
32}
33
34impl FromStr for EventType {
35    type Err = CqlEventParseError;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "TOPOLOGY_CHANGE" => Ok(Self::TopologyChange),
40            "STATUS_CHANGE" => Ok(Self::StatusChange),
41            "SCHEMA_CHANGE" => Ok(Self::SchemaChange),
42            _ => Err(CqlEventParseError::UnknownEventType(s.to_string())),
43        }
44    }
45}