use std::fmt;
use std::fmt::Display;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
#[cfg(feature = "zeroize")]
use zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Debug, Clone, PartialEq)]
pub struct RetrySettings {
pub max_attempts: u32,
pub delay_ms: u64,
}
impl Default for RetrySettings {
fn default() -> Self {
Self {
max_attempts: 0,
delay_ms: 1000,
}
}
}
pub const DEFAULT_PAGE_SIZE: usize = 100;
pub const MAX_PAGE_SIZE: usize = 500;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[must_use]
pub struct PaginationParams {
pub page: Option<usize>,
pub page_size: Option<usize>,
}
impl PaginationParams {
pub fn new(page: usize, page_size: usize) -> Self {
Self {
page: Some(page),
page_size: Some(page_size.min(MAX_PAGE_SIZE)),
}
}
pub fn first_page_default() -> Self {
Self::new(1, DEFAULT_PAGE_SIZE)
}
pub fn first_page(page_size: usize) -> Self {
Self::new(1, page_size)
}
pub fn to_query_string(&self) -> Option<String> {
match (self.page, self.page_size) {
(Some(page), Some(size)) => Some(format!("page={}&page_size={}", page, size)),
(Some(page), None) => Some(format!("page={}", page)),
(None, Some(size)) => Some(format!("page_size={}", size)),
(None, None) => None,
}
}
pub fn next_page(&self) -> Option<Self> {
self.page.map(|p| Self {
page: Some(p + 1),
page_size: self.page_size,
})
}
pub fn current_page(&self) -> Option<usize> {
self.page
}
pub fn page_size(&self) -> Option<usize> {
self.page_size
}
pub fn is_last_page<T>(&self, results: &[T]) -> bool {
let effective_page_size = self.page_size.unwrap_or(DEFAULT_PAGE_SIZE).max(1);
results.is_empty() || results.len() < effective_page_size
}
}
pub type Username = String;
pub type VirtualHostName = String;
pub type PermissionPattern = String;
pub type ChannelId = u32;
#[cfg(feature = "zeroize")]
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
pub struct Password(String);
#[cfg(feature = "zeroize")]
impl Password {
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
}
#[cfg(feature = "zeroize")]
impl fmt::Debug for Password {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Password([REDACTED])")
}
}
#[cfg(feature = "zeroize")]
impl Display for Password {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
#[cfg(feature = "zeroize")]
impl From<String> for Password {
fn from(value: String) -> Self {
Self(value)
}
}
#[cfg(feature = "zeroize")]
impl From<&str> for Password {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Hash)]
#[serde(rename_all(serialize = "lowercase", deserialize = "PascalCase"))]
pub enum SupportedProtocol {
Clustering,
#[serde(rename = "amqp", alias = "amqp091", alias = "amqp10")]
AMQP,
#[serde(rename = "amqp/ssl")]
AMQPWithTLS,
#[serde(rename = "stream")]
Stream,
#[serde(rename = "stream/ssl")]
StreamWithTLS,
#[serde(rename = "mqtt")]
MQTT,
#[serde(rename = "mqtt/ssl")]
MQTTWithTLS,
#[serde(rename = "stomp")]
STOMP,
#[serde(rename = "stomp/ssl")]
STOMPWithTLS,
#[serde(rename = "http/web-amqp")]
AMQPOverWebSockets,
#[serde(rename = "https/web-amqp")]
AMQPOverWebSocketsWithTLS,
#[serde(rename = "http/web-mqtt")]
MQTTOverWebSockets,
#[serde(rename = "https/web-mqtt")]
MQTTOverWebSocketsWithTLS,
#[serde(rename = "http/web-stomp")]
STOMPOverWebsockets,
#[serde(rename = "https/web-stomp")]
STOMPOverWebsocketsWithTLS,
#[serde(rename = "http/prometheus")]
Prometheus,
#[serde(rename = "https/prometheus")]
PrometheusWithTLS,
#[serde(rename = "http")]
HTTP,
#[serde(rename = "https")]
HTTPWithTLS,
Other(String),
}
pub const SUPPORTED_PROTOCOL_CLUSTERING: &str = "clustering";
pub const SUPPORTED_PROTOCOL_AMQP: &str = "amqp";
pub const SUPPORTED_PROTOCOL_AMQP_WITH_TLS: &str = "amqps";
pub const SUPPORTED_PROTOCOL_STREAM: &str = "stream";
pub const SUPPORTED_PROTOCOL_STREAM_WITH_TLS: &str = "stream/ssl";
pub const SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS: &str = "http/web-amqp";
pub const SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS_WITH_TLS: &str = "https/web-amqp";
pub const SUPPORTED_PROTOCOL_MQTT: &str = "mqtt";
pub const SUPPORTED_PROTOCOL_MQTT_WITH_TLS: &str = "mqtt/ssl";
pub const SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS: &str = "http/web-mqtt";
pub const SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS_WITH_TLS: &str = "https/web-mqtt";
pub const SUPPORTED_PROTOCOL_STOMP: &str = "stomp";
pub const SUPPORTED_PROTOCOL_STOMP_WITH_TLS: &str = "stomp/ssl";
pub const SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS: &str = "http/stomp-mqtt";
pub const SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS_WITH_TLS: &str = "https/stomp-mqtt";
pub const SUPPORTED_PROTOCOL_PROMETHEUS: &str = "http/prometheus";
pub const SUPPORTED_PROTOCOL_PROMETHEUS_WITH_TLS: &str = "https/prometheus";
pub const SUPPORTED_PROTOCOL_HTTP: &str = "http";
pub const SUPPORTED_PROTOCOL_HTTP_WITH_TLS: &str = "https";
impl From<&str> for SupportedProtocol {
fn from(value: &str) -> Self {
match value {
SUPPORTED_PROTOCOL_CLUSTERING => SupportedProtocol::Clustering,
SUPPORTED_PROTOCOL_AMQP => SupportedProtocol::AMQP,
SUPPORTED_PROTOCOL_AMQP_WITH_TLS => SupportedProtocol::AMQPWithTLS,
SUPPORTED_PROTOCOL_STREAM => SupportedProtocol::Stream,
SUPPORTED_PROTOCOL_STREAM_WITH_TLS => SupportedProtocol::StreamWithTLS,
SUPPORTED_PROTOCOL_MQTT => SupportedProtocol::MQTT,
SUPPORTED_PROTOCOL_MQTT_WITH_TLS => SupportedProtocol::MQTTWithTLS,
SUPPORTED_PROTOCOL_STOMP => SupportedProtocol::STOMP,
SUPPORTED_PROTOCOL_STOMP_WITH_TLS => SupportedProtocol::STOMPWithTLS,
SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS => SupportedProtocol::AMQPOverWebSockets,
SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS_WITH_TLS => {
SupportedProtocol::AMQPOverWebSocketsWithTLS
}
SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS => SupportedProtocol::MQTTOverWebSockets,
SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS_WITH_TLS => {
SupportedProtocol::MQTTOverWebSocketsWithTLS
}
SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS => SupportedProtocol::STOMPOverWebsockets,
SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS_WITH_TLS => {
SupportedProtocol::STOMPOverWebsocketsWithTLS
}
SUPPORTED_PROTOCOL_PROMETHEUS => SupportedProtocol::Prometheus,
SUPPORTED_PROTOCOL_PROMETHEUS_WITH_TLS => SupportedProtocol::PrometheusWithTLS,
SUPPORTED_PROTOCOL_HTTP => SupportedProtocol::HTTP,
SUPPORTED_PROTOCOL_HTTP_WITH_TLS => SupportedProtocol::HTTPWithTLS,
other => SupportedProtocol::Other(other.to_owned()),
}
}
}
impl From<String> for SupportedProtocol {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for SupportedProtocol {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for SupportedProtocol {
fn as_ref(&self) -> &str {
match self {
SupportedProtocol::Clustering => SUPPORTED_PROTOCOL_CLUSTERING,
SupportedProtocol::AMQP => SUPPORTED_PROTOCOL_AMQP,
SupportedProtocol::AMQPWithTLS => SUPPORTED_PROTOCOL_AMQP_WITH_TLS,
SupportedProtocol::Stream => SUPPORTED_PROTOCOL_STREAM,
SupportedProtocol::StreamWithTLS => SUPPORTED_PROTOCOL_STREAM_WITH_TLS,
SupportedProtocol::MQTT => SUPPORTED_PROTOCOL_MQTT,
SupportedProtocol::MQTTWithTLS => SUPPORTED_PROTOCOL_MQTT_WITH_TLS,
SupportedProtocol::STOMP => SUPPORTED_PROTOCOL_STOMP,
SupportedProtocol::STOMPWithTLS => SUPPORTED_PROTOCOL_STOMP_WITH_TLS,
SupportedProtocol::AMQPOverWebSockets => SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS,
SupportedProtocol::AMQPOverWebSocketsWithTLS => {
SUPPORTED_PROTOCOL_AMQP_OVER_WEBSOCKETS_WITH_TLS
}
SupportedProtocol::MQTTOverWebSockets => SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS,
SupportedProtocol::MQTTOverWebSocketsWithTLS => {
SUPPORTED_PROTOCOL_MQTT_OVER_WEBSOCKETS_WITH_TLS
}
SupportedProtocol::STOMPOverWebsockets => SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS,
SupportedProtocol::STOMPOverWebsocketsWithTLS => {
SUPPORTED_PROTOCOL_STOMP_OVER_WEBSOCKETS_WITH_TLS
}
SupportedProtocol::Prometheus => SUPPORTED_PROTOCOL_PROMETHEUS,
SupportedProtocol::PrometheusWithTLS => SUPPORTED_PROTOCOL_PROMETHEUS_WITH_TLS,
SupportedProtocol::HTTP => SUPPORTED_PROTOCOL_HTTP,
SupportedProtocol::HTTPWithTLS => SUPPORTED_PROTOCOL_HTTP_WITH_TLS,
SupportedProtocol::Other(s) => s.as_str(),
}
}
}
impl From<SupportedProtocol> for String {
fn from(value: SupportedProtocol) -> String {
match value {
SupportedProtocol::Other(s) => s,
other => other.as_ref().to_owned(),
}
}
}
impl From<&SupportedProtocol> for String {
fn from(value: &SupportedProtocol) -> Self {
value.clone().into()
}
}
impl fmt::Display for SupportedProtocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", String::from(self))
}
}
#[derive(Eq, PartialEq, Serialize, Deserialize, Debug, Clone, Hash)]
#[serde(rename_all(serialize = "lowercase", deserialize = "PascalCase"))]
pub enum ExchangeType {
Fanout,
Topic,
Direct,
Headers,
#[serde(rename = "x-consistent-hash")]
ConsistentHashing,
#[serde(rename = "x-modulus-hash")]
ModulusHash,
#[serde(rename = "x-random")]
Random,
#[serde(rename = "x-local-random")]
LocalRandom,
#[serde(rename = "x-jms-topic")]
JmsTopic,
#[serde(rename = "x-recent-history")]
RecentHistory,
#[serde(rename = "x-delayed-message")]
DelayedMessage,
#[serde(rename = "x-message-deduplication")]
MessageDeduplication,
#[serde(untagged)]
Plugin(String),
}
pub const X_ARGUMENT_KEY_X_QUEUE_TYPE: &str = "x-queue-type";
pub const X_ARGUMENT_KEY_X_OVERFLOW: &str = "x-overflow";
pub const EXCHANGE_TYPE_FANOUT: &str = "fanout";
pub const EXCHANGE_TYPE_TOPIC: &str = "topic";
pub const EXCHANGE_TYPE_DIRECT: &str = "direct";
pub const EXCHANGE_TYPE_HEADERS: &str = "headers";
pub const EXCHANGE_TYPE_CONSISTENT_HASHING: &str = "x-consistent-hash";
pub const EXCHANGE_TYPE_MODULUS_HASH: &str = "x-modulus-hash";
pub const EXCHANGE_TYPE_RANDOM: &str = "x-random";
pub const EXCHANGE_TYPE_JMS_TOPIC: &str = "x-jms-topic";
pub const EXCHANGE_TYPE_LOCAL_RANDOM: &str = "x-local-random";
pub const EXCHANGE_TYPE_RECENT_HISTORY: &str = "x-recent-history";
pub const EXCHANGE_TYPE_DELAYED_MESSAGE: &str = "x-delayed-message";
pub const EXCHANGE_TYPE_MESSAGE_DEDUPLICATION: &str = "x-message-deduplication";
impl From<&str> for ExchangeType {
fn from(value: &str) -> Self {
match value {
EXCHANGE_TYPE_FANOUT => ExchangeType::Fanout,
EXCHANGE_TYPE_TOPIC => ExchangeType::Topic,
EXCHANGE_TYPE_DIRECT => ExchangeType::Direct,
EXCHANGE_TYPE_HEADERS => ExchangeType::Headers,
EXCHANGE_TYPE_CONSISTENT_HASHING => ExchangeType::ConsistentHashing,
EXCHANGE_TYPE_MODULUS_HASH => ExchangeType::ModulusHash,
EXCHANGE_TYPE_RANDOM => ExchangeType::Random,
EXCHANGE_TYPE_LOCAL_RANDOM => ExchangeType::LocalRandom,
EXCHANGE_TYPE_JMS_TOPIC => ExchangeType::JmsTopic,
EXCHANGE_TYPE_RECENT_HISTORY => ExchangeType::RecentHistory,
EXCHANGE_TYPE_DELAYED_MESSAGE => ExchangeType::DelayedMessage,
EXCHANGE_TYPE_MESSAGE_DEDUPLICATION => ExchangeType::MessageDeduplication,
other => ExchangeType::Plugin(other.to_owned()),
}
}
}
impl From<String> for ExchangeType {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for ExchangeType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for ExchangeType {
fn as_ref(&self) -> &str {
match self {
ExchangeType::Fanout => EXCHANGE_TYPE_FANOUT,
ExchangeType::Topic => EXCHANGE_TYPE_TOPIC,
ExchangeType::Direct => EXCHANGE_TYPE_DIRECT,
ExchangeType::Headers => EXCHANGE_TYPE_HEADERS,
ExchangeType::ConsistentHashing => EXCHANGE_TYPE_CONSISTENT_HASHING,
ExchangeType::ModulusHash => EXCHANGE_TYPE_MODULUS_HASH,
ExchangeType::Random => EXCHANGE_TYPE_RANDOM,
ExchangeType::LocalRandom => EXCHANGE_TYPE_LOCAL_RANDOM,
ExchangeType::JmsTopic => EXCHANGE_TYPE_JMS_TOPIC,
ExchangeType::RecentHistory => EXCHANGE_TYPE_RECENT_HISTORY,
ExchangeType::DelayedMessage => EXCHANGE_TYPE_DELAYED_MESSAGE,
ExchangeType::MessageDeduplication => EXCHANGE_TYPE_MESSAGE_DEDUPLICATION,
ExchangeType::Plugin(s) => s,
}
}
}
impl From<ExchangeType> for String {
fn from(value: ExchangeType) -> String {
match value {
ExchangeType::Plugin(s) => s,
other => other.as_ref().to_owned(),
}
}
}
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Default, Hash)]
#[serde(rename_all(serialize = "lowercase", deserialize = "PascalCase"))]
pub enum QueueType {
#[default]
Classic,
Quorum,
Stream,
Delayed,
#[serde(untagged)]
Unsupported(String),
}
impl Display for QueueType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
QueueType::Classic => write!(f, "classic"),
QueueType::Quorum => write!(f, "quorum"),
QueueType::Stream => write!(f, "stream"),
QueueType::Delayed => write!(f, "delayed"),
QueueType::Unsupported(s) => write!(f, "{s}"),
}
}
}
impl From<&str> for QueueType {
fn from(value: &str) -> Self {
let val = value.to_ascii_lowercase();
match val.as_str() {
"classic" => QueueType::Classic,
"quorum" => QueueType::Quorum,
"stream" => QueueType::Stream,
"delayed" => QueueType::Delayed,
_ => QueueType::Unsupported(value.to_owned()),
}
}
}
impl From<String> for QueueType {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for QueueType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for QueueType {
fn as_ref(&self) -> &str {
match self {
QueueType::Classic => "classic",
QueueType::Quorum => "quorum",
QueueType::Stream => "stream",
QueueType::Delayed => "delayed",
QueueType::Unsupported(s) => s.as_str(),
}
}
}
impl From<QueueType> for String {
fn from(value: QueueType) -> Self {
match value {
QueueType::Unsupported(s) => s,
other => other.as_ref().to_owned(),
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum BindingDestinationType {
Queue,
Exchange,
}
impl fmt::Display for BindingDestinationType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BindingDestinationType::Queue => write!(f, "queue")?,
BindingDestinationType::Exchange => write!(f, "exchange")?,
};
Ok(())
}
}
impl BindingDestinationType {
pub fn path_abbreviation(&self) -> String {
match *self {
BindingDestinationType::Queue => "q".to_owned(),
BindingDestinationType::Exchange => "e".to_owned(),
}
}
}
impl From<&str> for BindingDestinationType {
fn from(value: &str) -> Self {
match value {
"queue" => BindingDestinationType::Queue,
"exchange" => BindingDestinationType::Exchange,
_ => BindingDestinationType::Queue,
}
}
}
impl From<String> for BindingDestinationType {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for BindingDestinationType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BindingVertex {
Source,
Destination,
}
impl AsRef<str> for BindingVertex {
fn as_ref(&self) -> &str {
match self {
Self::Source => "source",
Self::Destination => "destination",
}
}
}
impl AsRef<str> for BindingDestinationType {
fn as_ref(&self) -> &str {
match self {
BindingDestinationType::Queue => "queue",
BindingDestinationType::Exchange => "exchange",
}
}
}
impl From<BindingDestinationType> for String {
fn from(value: BindingDestinationType) -> Self {
match value {
BindingDestinationType::Queue => "queue".to_owned(),
BindingDestinationType::Exchange => "exchange".to_owned(),
}
}
}
#[derive(Eq, PartialEq, Debug, Deserialize, Serialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum PolicyTarget {
Queues,
ClassicQueues,
QuorumQueues,
Streams,
Exchanges,
All,
}
impl From<QueueType> for PolicyTarget {
fn from(value: QueueType) -> Self {
match value {
QueueType::Classic => PolicyTarget::ClassicQueues,
QueueType::Quorum => PolicyTarget::QuorumQueues,
QueueType::Stream => PolicyTarget::Streams,
QueueType::Delayed => PolicyTarget::Queues,
QueueType::Unsupported(_) => PolicyTarget::Queues,
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "kebab-case")]
pub enum OverflowBehavior {
DropHead,
RejectPublish,
RejectPublishDlx,
}
pub const OVERFLOW_REJECT_PUBLISH: &str = "reject-publish";
pub const OVERFLOW_REJECT_PUBLISH_DLX: &str = "reject-publish-dlx";
pub const OVERFLOW_DROP_HEAD: &str = "drop-head";
impl From<OverflowBehavior> for &str {
fn from(value: OverflowBehavior) -> Self {
match value {
OverflowBehavior::DropHead => OVERFLOW_DROP_HEAD,
OverflowBehavior::RejectPublish => OVERFLOW_REJECT_PUBLISH,
OverflowBehavior::RejectPublishDlx => OVERFLOW_REJECT_PUBLISH_DLX,
}
}
}
impl From<&str> for OverflowBehavior {
fn from(s: &str) -> Self {
match s {
OVERFLOW_DROP_HEAD => OverflowBehavior::DropHead,
OVERFLOW_REJECT_PUBLISH => OverflowBehavior::RejectPublish,
OVERFLOW_REJECT_PUBLISH_DLX => OverflowBehavior::RejectPublishDlx,
_ => OverflowBehavior::DropHead,
}
}
}
impl From<String> for OverflowBehavior {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for OverflowBehavior {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl From<OverflowBehavior> for String {
fn from(value: OverflowBehavior) -> Self {
let s: &str = value.into();
s.to_owned()
}
}
impl PolicyTarget {
pub fn does_apply_to(&self, other: PolicyTarget) -> bool {
match (self, other) {
(PolicyTarget::All, _) => true,
(_, PolicyTarget::All) => true,
(PolicyTarget::Queues, PolicyTarget::Queues) => true,
(PolicyTarget::Queues, PolicyTarget::ClassicQueues) => true,
(PolicyTarget::Queues, PolicyTarget::QuorumQueues) => true,
(PolicyTarget::Queues, PolicyTarget::Streams) => true,
(PolicyTarget::ClassicQueues, PolicyTarget::ClassicQueues) => true,
(PolicyTarget::QuorumQueues, PolicyTarget::QuorumQueues) => true,
(PolicyTarget::Streams, PolicyTarget::Streams) => true,
(PolicyTarget::Exchanges, PolicyTarget::Exchanges) => true,
_ => false,
}
}
}
impl fmt::Display for PolicyTarget {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", Into::<String>::into(*self))?;
Ok(())
}
}
impl From<&str> for PolicyTarget {
fn from(value: &str) -> Self {
match value {
"queues" => PolicyTarget::Queues,
"queue" => PolicyTarget::Queues,
"classic_queues" => PolicyTarget::ClassicQueues,
"classic_queue" => PolicyTarget::ClassicQueues,
"quorum_queues" => PolicyTarget::QuorumQueues,
"quorum_queue" => PolicyTarget::QuorumQueues,
"streams" => PolicyTarget::Streams,
"stream" => PolicyTarget::Streams,
"exchanges" => PolicyTarget::Exchanges,
"exchange" => PolicyTarget::Exchanges,
"all" => PolicyTarget::All,
_ => PolicyTarget::Queues,
}
}
}
impl From<String> for PolicyTarget {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for PolicyTarget {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for PolicyTarget {
fn as_ref(&self) -> &str {
match self {
PolicyTarget::Queues => "queues",
PolicyTarget::ClassicQueues => "classic_queues",
PolicyTarget::QuorumQueues => "quorum_queues",
PolicyTarget::Streams => "streams",
PolicyTarget::Exchanges => "exchanges",
PolicyTarget::All => "all",
}
}
}
impl From<PolicyTarget> for String {
fn from(value: PolicyTarget) -> Self {
match value {
PolicyTarget::Queues => "queues".to_owned(),
PolicyTarget::ClassicQueues => "classic_queues".to_owned(),
PolicyTarget::QuorumQueues => "quorum_queues".to_owned(),
PolicyTarget::Streams => "streams".to_owned(),
PolicyTarget::Exchanges => "exchanges".to_owned(),
PolicyTarget::All => "all".to_owned(),
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum VirtualHostLimitTarget {
MaxConnections,
MaxQueues,
}
impl AsRef<str> for VirtualHostLimitTarget {
fn as_ref(&self) -> &str {
match self {
VirtualHostLimitTarget::MaxConnections => "max-connections",
VirtualHostLimitTarget::MaxQueues => "max-queues",
}
}
}
impl From<&str> for VirtualHostLimitTarget {
fn from(value: &str) -> Self {
match value {
"max-connections" => VirtualHostLimitTarget::MaxConnections,
"max-queues" => VirtualHostLimitTarget::MaxQueues,
_ => VirtualHostLimitTarget::MaxConnections,
}
}
}
impl From<String> for VirtualHostLimitTarget {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for VirtualHostLimitTarget {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl From<VirtualHostLimitTarget> for String {
fn from(value: VirtualHostLimitTarget) -> Self {
value.as_ref().to_string()
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(untagged, rename_all = "kebab-case")]
pub enum UserLimitTarget {
MaxConnections,
MaxChannels,
}
impl AsRef<str> for UserLimitTarget {
fn as_ref(&self) -> &str {
match self {
UserLimitTarget::MaxConnections => "max-connections",
UserLimitTarget::MaxChannels => "max-channels",
}
}
}
impl From<&str> for UserLimitTarget {
fn from(value: &str) -> Self {
match value {
"max-connections" => UserLimitTarget::MaxConnections,
"max-channels" => UserLimitTarget::MaxChannels,
_ => UserLimitTarget::MaxConnections,
}
}
}
impl From<String> for UserLimitTarget {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for UserLimitTarget {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl From<UserLimitTarget> for String {
fn from(value: UserLimitTarget) -> Self {
value.as_ref().to_string()
}
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "snake_case")]
pub enum TlsPeerVerificationMode {
#[default]
Enabled,
Disabled,
}
pub const TLS_PEER_VERIFICATION_KEY: &str = "verify";
pub const TLS_PEER_VERIFICATION_VERIFY_PEER: &str = "verify_peer";
pub const TLS_PEER_VERIFICATION_VERIFY_NONE: &str = "verify_none";
impl From<&str> for TlsPeerVerificationMode {
fn from(value: &str) -> Self {
match value {
TLS_PEER_VERIFICATION_VERIFY_PEER => TlsPeerVerificationMode::Enabled,
TLS_PEER_VERIFICATION_VERIFY_NONE => TlsPeerVerificationMode::Disabled,
_ => TlsPeerVerificationMode::Enabled,
}
}
}
impl From<String> for TlsPeerVerificationMode {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for TlsPeerVerificationMode {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for TlsPeerVerificationMode {
fn as_ref(&self) -> &str {
match self {
TlsPeerVerificationMode::Enabled => TLS_PEER_VERIFICATION_VERIFY_PEER,
TlsPeerVerificationMode::Disabled => TLS_PEER_VERIFICATION_VERIFY_NONE,
}
}
}
impl From<TlsPeerVerificationMode> for String {
fn from(value: TlsPeerVerificationMode) -> Self {
match value {
TlsPeerVerificationMode::Enabled => TLS_PEER_VERIFICATION_VERIFY_PEER.to_owned(),
TlsPeerVerificationMode::Disabled => TLS_PEER_VERIFICATION_VERIFY_NONE.to_owned(),
}
}
}
impl From<&TlsPeerVerificationMode> for String {
fn from(value: &TlsPeerVerificationMode) -> Self {
value.clone().into()
}
}
impl fmt::Display for TlsPeerVerificationMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", String::from(self))
}
}
#[derive(Default, Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub enum MessageTransferAcknowledgementMode {
#[serde(rename = "no-ack")]
Immediate,
#[serde(rename = "on-publish")]
WhenPublished,
#[default]
#[serde(rename = "on-confirm")]
WhenConfirmed,
}
impl From<&str> for MessageTransferAcknowledgementMode {
fn from(value: &str) -> Self {
match value {
"no-ack" => MessageTransferAcknowledgementMode::Immediate,
"on-publish" => MessageTransferAcknowledgementMode::WhenPublished,
"on-confirm" => MessageTransferAcknowledgementMode::WhenConfirmed,
_ => MessageTransferAcknowledgementMode::default(),
}
}
}
impl From<String> for MessageTransferAcknowledgementMode {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for MessageTransferAcknowledgementMode {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for MessageTransferAcknowledgementMode {
fn as_ref(&self) -> &str {
match self {
MessageTransferAcknowledgementMode::Immediate => "no-ack",
MessageTransferAcknowledgementMode::WhenPublished => "on-publish",
MessageTransferAcknowledgementMode::WhenConfirmed => "on-confirm",
}
}
}
impl Display for MessageTransferAcknowledgementMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MessageTransferAcknowledgementMode::Immediate => write!(f, "no-ack"),
MessageTransferAcknowledgementMode::WhenPublished => write!(f, "on-publish"),
MessageTransferAcknowledgementMode::WhenConfirmed => write!(f, "on-confirm"),
}
}
}
impl From<MessageTransferAcknowledgementMode> for String {
fn from(value: MessageTransferAcknowledgementMode) -> Self {
value.to_string()
}
}
#[derive(Default, Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ChannelUseMode {
#[default]
Multiple,
Single,
}
impl From<&str> for ChannelUseMode {
fn from(value: &str) -> Self {
match value.to_lowercase().as_str() {
"multiple" => ChannelUseMode::Multiple,
"single" => ChannelUseMode::Single,
_ => ChannelUseMode::default(),
}
}
}
impl From<String> for ChannelUseMode {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl FromStr for ChannelUseMode {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from(s))
}
}
impl AsRef<str> for ChannelUseMode {
fn as_ref(&self) -> &str {
match self {
ChannelUseMode::Multiple => "multiple",
ChannelUseMode::Single => "single",
}
}
}
impl Display for ChannelUseMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ChannelUseMode::Multiple => write!(f, "multiple"),
ChannelUseMode::Single => write!(f, "single"),
}
}
}
impl From<ChannelUseMode> for String {
fn from(value: ChannelUseMode) -> Self {
value.to_string()
}
}