use kafka_client_core::{
ClientQuotaMatch as CoreMatch, DescribeClientQuotaFilterComponent as CoreFilterComponent,
DescribeClientQuotasPlan as CorePlan, DescribeClientQuotasPlanError as CorePlanError,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum DescribeClientQuotaMatch {
Exact(String),
Default,
AnySpecified,
}
impl DescribeClientQuotaMatch {
fn into_core(self) -> CoreMatch {
match self {
Self::Exact(name) => CoreMatch::Exact(canonical_string(name)),
Self::Default => CoreMatch::Default,
Self::AnySpecified => CoreMatch::AnySpecified,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DescribeClientQuotaFilterComponent {
entity_type: String,
selection: DescribeClientQuotaMatch,
}
impl DescribeClientQuotaFilterComponent {
pub fn new(entity_type: String, selection: DescribeClientQuotaMatch) -> Self {
Self {
entity_type,
selection,
}
}
pub fn entity_type(&self) -> &str {
&self.entity_type
}
pub const fn selection(&self) -> &DescribeClientQuotaMatch {
&self.selection
}
pub fn into_parts(self) -> (String, DescribeClientQuotaMatch) {
(self.entity_type, self.selection)
}
fn into_core(self) -> CoreFilterComponent {
CoreFilterComponent::new(
canonical_string(self.entity_type),
self.selection.into_core(),
)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DescribeClientQuotasRequest {
components: Vec<DescribeClientQuotaFilterComponent>,
strict: bool,
}
impl DescribeClientQuotasRequest {
pub fn new(components: Vec<DescribeClientQuotaFilterComponent>, strict: bool) -> Self {
Self { components, strict }
}
pub fn components(&self) -> &[DescribeClientQuotaFilterComponent] {
&self.components
}
pub const fn strict(&self) -> bool {
self.strict
}
pub fn into_parts(self) -> (Vec<DescribeClientQuotaFilterComponent>, bool) {
(self.components, self.strict)
}
pub(crate) fn canonicalize(mut self) -> Self {
self.components.shrink_to_fit();
self
}
pub(crate) fn into_plan(self) -> Result<CorePlan, CorePlanError> {
let (components, strict) = self.into_parts();
CorePlan::new(
components
.into_iter()
.map(DescribeClientQuotaFilterComponent::into_core)
.collect(),
strict,
)
}
}
fn canonical_string(value: String) -> String {
value.into_boxed_str().into_string()
}