Skip to main content

kafka_client_engine/admin/list_share_group_offsets/
outcome.rs

1//! Stable generated-free singular and batch terminals for `ListShareGroupOffsets`.
2
3use core::fmt;
4
5mod translate;
6
7pub(crate) use translate::translate_terminal;
8
9use super::ListShareGroupOffsetsBatch;
10
11/// Stable delivery certainty independent of core and driver types.
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub enum ListShareGroupOffsetsDeliveryStatus {
14    /// The failed call did not reach Kafka.
15    NotSent,
16    /// The failed call may have reached Kafka.
17    PossiblySent,
18}
19
20/// Exact top-level Kafka rejection and its bounded diagnostic.
21#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct ListShareGroupOffsetsBrokerError {
23    pub(super) throttle_time_ms: u32,
24    pub(super) code: i16,
25    pub(super) message: Option<String>,
26    pub(super) message_truncated: bool,
27}
28
29impl ListShareGroupOffsetsBrokerError {
30    /// Returns Kafka's nonnegative throttle observation.
31    pub const fn throttle_time_ms(&self) -> u32 {
32        self.throttle_time_ms
33    }
34
35    /// Returns Kafka's exact signed nonzero error code.
36    pub const fn code(&self) -> i16 {
37        self.code
38    }
39
40    /// Returns Kafka's optional bounded diagnostic.
41    pub fn message(&self) -> Option<&str> {
42        self.message.as_deref()
43    }
44
45    /// Reports whether the diagnostic was truncated at the retained-byte bound.
46    pub const fn message_truncated(&self) -> bool {
47        self.message_truncated
48    }
49
50    /// Consumes the rejection into exact stable parts.
51    pub fn into_parts(self) -> (u32, i16, Option<String>, bool) {
52        (
53            self.throttle_time_ms,
54            self.code,
55            self.message,
56            self.message_truncated,
57        )
58    }
59}
60
61/// Exact result for one share group in a caller-ordered batch.
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum ListShareGroupOffsetsBatchOutcome {
64    /// Kafka returned correlated partition outcomes for this group.
65    Offsets {
66        /// Exact requested share-group identity.
67        group_id: String,
68        /// Canonically or caller-ordered partition outcomes.
69        offsets: ListShareGroupOffsetsBatch,
70    },
71    /// Kafka rejected this specific share group.
72    BrokerRejected {
73        /// Exact requested share-group identity.
74        group_id: String,
75        /// Exact signed group rejection.
76        error: ListShareGroupOffsetsBrokerError,
77    },
78}
79
80impl ListShareGroupOffsetsBatchOutcome {
81    /// Returns the exact requested share-group identity.
82    pub fn group_id(&self) -> &str {
83        match self {
84            Self::Offsets { group_id, .. } | Self::BrokerRejected { group_id, .. } => group_id,
85        }
86    }
87}
88
89/// Caller-ordered multi-group result plus maximum observed broker throttle.
90#[derive(Clone, Debug, Eq, PartialEq)]
91pub struct ListShareGroupsOffsetsBatch {
92    pub(super) throttle_time_ms: u32,
93    pub(super) outcomes: Vec<ListShareGroupOffsetsBatchOutcome>,
94}
95
96impl ListShareGroupsOffsetsBatch {
97    /// Returns the maximum throttle observed across coordinator calls.
98    pub const fn throttle_time_ms(&self) -> u32 {
99        self.throttle_time_ms
100    }
101
102    /// Returns exactly one outcome per requested group in caller order.
103    pub fn outcomes(&self) -> &[ListShareGroupOffsetsBatchOutcome] {
104        &self.outcomes
105    }
106
107    /// Consumes this batch into maximum throttle and caller-ordered outcomes.
108    pub fn into_parts(self) -> (u32, Vec<ListShareGroupOffsetsBatchOutcome>) {
109        (self.throttle_time_ms, self.outcomes)
110    }
111}
112
113/// Stable whole-operation failure category outside exact Kafka rejections.
114#[derive(Clone, Copy, Debug, Eq, PartialEq)]
115pub enum ListShareGroupOffsetsFailureKind {
116    /// The original public absolute deadline elapsed.
117    DeadlineElapsed,
118    /// Driver admission rejected the prepared request.
119    DriverRejected,
120    /// Driver-owned transport execution failed.
121    Transport,
122    /// Valid response facts exceeded admitted retained capacity.
123    ResponseTooLarge,
124    /// The selected API version cannot represent required semantics.
125    Compatibility,
126    /// A response was malformed or could not be normalized.
127    InvalidResponse,
128}
129
130/// Whole-operation failure with authoritative delivery certainty.
131#[derive(Clone, Copy, Debug, Eq, PartialEq)]
132pub struct ListShareGroupOffsetsFailure {
133    pub(super) kind: ListShareGroupOffsetsFailureKind,
134    pub(super) delivery: ListShareGroupOffsetsDeliveryStatus,
135}
136
137impl ListShareGroupOffsetsFailure {
138    /// Returns the stable failure category.
139    pub const fn kind(self) -> ListShareGroupOffsetsFailureKind {
140        self.kind
141    }
142
143    /// Returns authoritative delivery certainty.
144    pub const fn delivery(self) -> ListShareGroupOffsetsDeliveryStatus {
145        self.delivery
146    }
147}
148
149/// Exactly one engine-owned terminal decision.
150#[derive(Clone, Debug, Eq, PartialEq)]
151pub enum ListShareGroupOffsetsOutcome {
152    /// Kafka returned one result for every selected or visible partition.
153    Offsets(ListShareGroupOffsetsBatch),
154    /// Kafka rejected the group-level operation.
155    BrokerRejected(ListShareGroupOffsetsBrokerError),
156    /// Every requested group settled in original caller order.
157    Batch(ListShareGroupsOffsetsBatch),
158    /// Execution failed outside an exact Kafka rejection.
159    Failed(ListShareGroupOffsetsFailure),
160}
161
162/// Failure to observe one named completion.
163#[derive(Clone, Copy, Debug, Eq, PartialEq)]
164pub enum ListShareGroupOffsetsObserverError {
165    /// This linear observer already consumed its terminal.
166    AlreadyObserved,
167    /// The observer generation is no longer live.
168    Stale,
169}
170
171impl fmt::Display for ListShareGroupOffsetsObserverError {
172    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
173        formatter.write_str(match self {
174            Self::AlreadyObserved => "Admin ListShareGroupOffsets result was already observed",
175            Self::Stale => "Admin ListShareGroupOffsets observer is stale",
176        })
177    }
178}
179
180impl std::error::Error for ListShareGroupOffsetsObserverError {}