kafka_client_engine/admin/update_features/
model.rs1use kafka_client_core::{
4 UpdateFeature as CoreFeature, UpdateFeatureIntent as CoreIntent,
5 UpdateFeaturesPlan as CorePlan, UpdateFeaturesPlanError as CorePlanError,
6};
7
8pub(crate) enum UpdateFeaturesPlanFailure {
9 Invalid,
10 RetainedBytes,
11}
12
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub enum UpdateFeatureIntent {
16 Upgrade,
18 SafeDowngrade,
20 UnsafeDowngrade,
22}
23
24#[derive(Clone, Debug, Eq, PartialEq)]
26pub struct UpdateFeature {
27 feature: String,
28 max_version_level: i16,
29 intent: UpdateFeatureIntent,
30}
31
32impl UpdateFeature {
33 pub const fn new(feature: String, max_version_level: i16, intent: UpdateFeatureIntent) -> Self {
35 Self {
36 feature,
37 max_version_level,
38 intent,
39 }
40 }
41
42 pub fn feature(&self) -> &str {
44 &self.feature
45 }
46
47 pub const fn max_version_level(&self) -> i16 {
49 self.max_version_level
50 }
51
52 pub const fn intent(&self) -> UpdateFeatureIntent {
54 self.intent
55 }
56
57 fn to_core(&self) -> CoreFeature {
58 CoreFeature::new(
59 self.feature.clone().into_boxed_str().into_string(),
60 self.max_version_level,
61 match self.intent {
62 UpdateFeatureIntent::Upgrade => CoreIntent::Upgrade,
63 UpdateFeatureIntent::SafeDowngrade => CoreIntent::SafeDowngrade,
64 UpdateFeatureIntent::UnsafeDowngrade => CoreIntent::UnsafeDowngrade,
65 },
66 )
67 }
68}
69
70#[derive(Clone, Debug, Eq, PartialEq)]
72pub struct UpdateFeaturesRequest {
73 updates: Vec<UpdateFeature>,
74 validate_only: bool,
75}
76
77impl UpdateFeaturesRequest {
78 pub const fn new(updates: Vec<UpdateFeature>, validate_only: bool) -> Self {
80 Self {
81 updates,
82 validate_only,
83 }
84 }
85
86 pub fn updates(&self) -> &[UpdateFeature] {
88 &self.updates
89 }
90
91 pub const fn validate_only(&self) -> bool {
93 self.validate_only
94 }
95
96 pub(crate) fn plan(&self) -> Result<CorePlan, UpdateFeaturesPlanFailure> {
97 let mut updates = Vec::new();
98 updates
99 .try_reserve_exact(self.updates.len())
100 .map_err(|_| UpdateFeaturesPlanFailure::RetainedBytes)?;
101 updates.extend(self.updates.iter().map(UpdateFeature::to_core));
102 CorePlan::new(updates, self.validate_only)
103 .map_err(|_error: CorePlanError| UpdateFeaturesPlanFailure::Invalid)
104 }
105}