kafka_client_engine/admin/
delete_outcome.rs1use core::fmt;
4
5use kafka_client_core::{
6 DeleteTopicResult as CoreTopicResult, DeleteTopicsFailureKind as CoreFailureKind,
7 DeleteTopicsTerminal, DeliveryStatus as CoreDeliveryStatus,
8};
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum DeleteTopicsDeliveryStatus {
13 NotSent,
15 PossiblySent,
17}
18
19#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct DeleteTopicError {
22 code: i16,
23 message: Option<String>,
24 message_truncated: bool,
25}
26
27impl DeleteTopicError {
28 pub const fn code(&self) -> i16 {
30 self.code
31 }
32
33 pub fn message(&self) -> Option<&str> {
35 self.message.as_deref()
36 }
37
38 pub const fn message_truncated(&self) -> bool {
40 self.message_truncated
41 }
42
43 pub fn into_parts(self) -> (i16, Option<String>, bool) {
45 (self.code, self.message, self.message_truncated)
46 }
47}
48
49#[derive(Clone, Debug, Eq, PartialEq)]
51pub struct DeleteTopicResult {
52 topic: String,
53 result: Result<(), DeleteTopicError>,
54}
55
56#[derive(Clone, Debug, Eq, PartialEq)]
58pub struct DeleteTopicIdResult {
59 topic_id: [u8; 16],
60 result: Result<(), DeleteTopicError>,
61}
62
63impl DeleteTopicIdResult {
64 pub const fn topic_id(&self) -> [u8; 16] {
66 self.topic_id
67 }
68
69 pub const fn result(&self) -> &Result<(), DeleteTopicError> {
71 &self.result
72 }
73
74 pub fn into_parts(self) -> ([u8; 16], Result<(), DeleteTopicError>) {
76 (self.topic_id, self.result)
77 }
78}
79
80impl DeleteTopicResult {
81 pub fn topic(&self) -> &str {
83 &self.topic
84 }
85
86 pub const fn result(&self) -> &Result<(), DeleteTopicError> {
88 &self.result
89 }
90
91 pub fn into_parts(self) -> (String, Result<(), DeleteTopicError>) {
93 (self.topic, self.result)
94 }
95}
96
97#[derive(Clone, Copy, Debug, Eq, PartialEq)]
99pub enum DeleteTopicsFailureKind {
100 DeadlineElapsed,
102 DriverRejected,
104 Transport,
106 InvalidResponse,
108}
109
110#[derive(Clone, Copy, Debug, Eq, PartialEq)]
112pub struct DeleteTopicsFailure {
113 kind: DeleteTopicsFailureKind,
114 delivery: DeleteTopicsDeliveryStatus,
115}
116
117impl DeleteTopicsFailure {
118 pub const fn kind(self) -> DeleteTopicsFailureKind {
120 self.kind
121 }
122
123 pub const fn delivery(self) -> DeleteTopicsDeliveryStatus {
125 self.delivery
126 }
127}
128
129#[derive(Clone, Debug, Eq, PartialEq)]
131pub enum DeleteTopicsOutcome {
132 Topics(Vec<DeleteTopicResult>),
134 TopicIds(Vec<DeleteTopicIdResult>),
136 Failed(DeleteTopicsFailure),
138}
139
140#[derive(Clone, Copy, Debug, Eq, PartialEq)]
142pub enum DeleteTopicsObserverError {
143 AlreadyObserved,
145 Stale,
147}
148
149impl fmt::Display for DeleteTopicsObserverError {
150 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
151 formatter.write_str(match self {
152 Self::AlreadyObserved => "DeleteTopics result was already observed",
153 Self::Stale => "DeleteTopics observer is stale",
154 })
155 }
156}
157
158impl std::error::Error for DeleteTopicsObserverError {}
159
160pub(crate) fn translate_terminal(terminal: DeleteTopicsTerminal) -> DeleteTopicsOutcome {
161 match terminal {
162 DeleteTopicsTerminal::Topics(outcomes) => DeleteTopicsOutcome::Topics(
163 outcomes
164 .into_iter()
165 .map(|outcome| {
166 let (topic, result) = outcome.into_parts();
167 let result = match result {
168 CoreTopicResult::Deleted => Ok(()),
169 CoreTopicResult::Failed(error) => {
170 let (code, message, message_truncated) = error.into_parts();
171 Err(DeleteTopicError {
172 code,
173 message,
174 message_truncated,
175 })
176 }
177 };
178 DeleteTopicResult { topic, result }
179 })
180 .collect(),
181 ),
182 DeleteTopicsTerminal::TopicIds(outcomes) => DeleteTopicsOutcome::TopicIds(
183 outcomes
184 .into_iter()
185 .map(|outcome| {
186 let (topic_id, result) = outcome.into_parts();
187 let result = match result {
188 CoreTopicResult::Deleted => Ok(()),
189 CoreTopicResult::Failed(error) => {
190 let (code, message, message_truncated) = error.into_parts();
191 Err(DeleteTopicError {
192 code,
193 message,
194 message_truncated,
195 })
196 }
197 };
198 DeleteTopicIdResult { topic_id, result }
199 })
200 .collect(),
201 ),
202 DeleteTopicsTerminal::Failed(failure) => {
203 let kind = match failure.kind() {
204 CoreFailureKind::DeadlineElapsed => DeleteTopicsFailureKind::DeadlineElapsed,
205 CoreFailureKind::DriverRejected => DeleteTopicsFailureKind::DriverRejected,
206 CoreFailureKind::Transport => DeleteTopicsFailureKind::Transport,
207 CoreFailureKind::InvalidResponse => DeleteTopicsFailureKind::InvalidResponse,
208 };
209 DeleteTopicsOutcome::Failed(DeleteTopicsFailure {
210 kind,
211 delivery: match failure.delivery() {
212 CoreDeliveryStatus::NotSent => DeleteTopicsDeliveryStatus::NotSent,
213 CoreDeliveryStatus::PossiblySent => DeleteTopicsDeliveryStatus::PossiblySent,
214 },
215 })
216 }
217 }
218}