Skip to content

Commit eca1070

Browse files
Introduce responses::ChannelState
1 parent 8d55621 commit eca1070

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Enhancements
66

7+
* `responses::Channel#state` now uses an enum, `responses::ChannelState`, instead of a string.
78
* `Client#enable_vhost_deletion_protection` [protects](https://www.rabbitmq.com/docs/vhosts#deletion-protection) a virtual host from deletion (using the `POST /api/vhosts/{vhost}/deletion/protection` endpoint).
89
* `Client#disable_vhost_deletion_protection` lifts [deletion protection](https://www.rabbitmq.com/docs/vhosts#deletion-protection) (using the `DELETE /api/vhosts/{vhost}/deletion/protection` endpoint).
910
* `Client#auth_attempts_statistics` is a new function providing support for the `GET /api/auth/attempts/{node}` endpoint.

src/responses.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,44 @@ pub struct UserConnection {
747747
pub vhost: VirtualHostName,
748748
}
749749

750+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
751+
#[serde(rename_all = "lowercase")]
752+
pub enum ChannelState {
753+
Starting,
754+
Running,
755+
Closing,
756+
#[serde(untagged)]
757+
Unknown(String),
758+
}
759+
760+
impl From<&str> for ChannelState {
761+
fn from(value: &str) -> Self {
762+
match value {
763+
"starting" => ChannelState::Starting,
764+
"running" => ChannelState::Running,
765+
"closing" => ChannelState::Closing,
766+
other => ChannelState::Unknown(other.to_owned()),
767+
}
768+
}
769+
}
770+
771+
impl From<String> for ChannelState {
772+
fn from(value: String) -> Self {
773+
Self::from(value.as_str())
774+
}
775+
}
776+
777+
impl fmt::Display for ChannelState {
778+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
779+
match self {
780+
ChannelState::Starting => write!(f, "starting"),
781+
ChannelState::Running => write!(f, "running"),
782+
ChannelState::Closing => write!(f, "closing"),
783+
ChannelState::Unknown(s) => write!(f, "{}", s),
784+
}
785+
}
786+
}
787+
750788
#[derive(Debug, Deserialize, Clone)]
751789
#[cfg_attr(feature = "tabled", derive(Tabled))]
752790
#[allow(dead_code)]
@@ -757,7 +795,7 @@ pub struct Channel {
757795
#[cfg_attr(feature = "tabled", tabled(skip))]
758796
pub connection_details: ConnectionDetails,
759797
pub vhost: VirtualHostName,
760-
pub state: String,
798+
pub state: ChannelState,
761799
pub consumer_count: u32,
762800
#[serde(rename(deserialize = "confirm"))]
763801
pub has_publisher_confirms_enabled: bool,

0 commit comments

Comments
 (0)