Skip to main content

kafka_client_engine/admin/describe_streams_group/
outcome.rs

1//! Stable generated-free terminals for Admin `DescribeStreamsGroup`.
2
3use core::fmt;
4
5mod translate;
6
7pub(crate) use translate::translate_terminal;
8
9use super::DescribeStreamsGroupResult;
10
11/// Stable delivery certainty independent of core and driver types.
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub enum DescribeStreamsGroupDeliveryStatus {
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 DescribeStreamsGroupBrokerError {
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 DescribeStreamsGroupBrokerError {
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/// Stable whole-operation failure category outside exact Kafka rejections.
62#[derive(Clone, Copy, Debug, Eq, PartialEq)]
63pub enum DescribeStreamsGroupFailureKind {
64    /// The original public absolute deadline elapsed.
65    DeadlineElapsed,
66    /// Driver admission rejected the prepared request.
67    DriverRejected,
68    /// Driver-owned transport execution failed.
69    Transport,
70    /// Valid response facts exceeded admitted retained capacity.
71    ResponseTooLarge,
72    /// The selected API version cannot represent required semantics.
73    Compatibility,
74    /// A response was malformed or could not be normalized.
75    InvalidResponse,
76}
77
78/// Whole-operation failure with authoritative delivery certainty.
79#[derive(Clone, Copy, Debug, Eq, PartialEq)]
80pub struct DescribeStreamsGroupFailure {
81    pub(super) kind: DescribeStreamsGroupFailureKind,
82    pub(super) delivery: DescribeStreamsGroupDeliveryStatus,
83}
84
85impl DescribeStreamsGroupFailure {
86    /// Returns the stable failure category.
87    pub const fn kind(self) -> DescribeStreamsGroupFailureKind {
88        self.kind
89    }
90
91    /// Returns authoritative delivery certainty.
92    pub const fn delivery(self) -> DescribeStreamsGroupDeliveryStatus {
93        self.delivery
94    }
95}
96
97/// Exact result for one streams group in a caller-ordered batch.
98#[derive(Clone, Debug, Eq, PartialEq)]
99pub enum DescribeStreamsGroupBatchOutcome {
100    /// Kafka returned one exact streams-group description.
101    Described(DescribeStreamsGroupResult),
102    /// Kafka rejected this exact streams group.
103    BrokerRejected {
104        /// Exact requested streams-group identity.
105        group_id: String,
106        /// Exact signed rejection, throttle, and bounded diagnostic.
107        error: DescribeStreamsGroupBrokerError,
108    },
109}
110
111impl DescribeStreamsGroupBatchOutcome {
112    /// Returns the exact requested streams-group identity.
113    pub fn group_id(&self) -> &str {
114        match self {
115            Self::Described(result) => result.description().group_id(),
116            Self::BrokerRejected { group_id, .. } => group_id,
117        }
118    }
119
120    /// Returns this group's nonnegative Kafka throttle observation.
121    pub const fn throttle_time_ms(&self) -> u32 {
122        match self {
123            Self::Described(result) => result.throttle_time_ms(),
124            Self::BrokerRejected { error, .. } => error.throttle_time_ms(),
125        }
126    }
127}
128
129/// Caller-ordered outcomes for one accepted streams-group batch.
130#[derive(Clone, Debug, Eq, PartialEq)]
131pub struct DescribeStreamsGroupsBatch {
132    throttle_time_ms: u32,
133    outcomes: Vec<DescribeStreamsGroupBatchOutcome>,
134}
135
136impl DescribeStreamsGroupsBatch {
137    /// Returns the maximum nonnegative throttle observed across coordinator calls.
138    pub const fn throttle_time_ms(&self) -> u32 {
139        self.throttle_time_ms
140    }
141
142    /// Returns exactly one outcome per requested group in caller order.
143    pub fn outcomes(&self) -> &[DescribeStreamsGroupBatchOutcome] {
144        &self.outcomes
145    }
146
147    /// Consumes the batch into maximum throttle and caller-ordered outcomes.
148    pub fn into_parts(self) -> (u32, Vec<DescribeStreamsGroupBatchOutcome>) {
149        (self.throttle_time_ms, self.outcomes)
150    }
151}
152
153/// Exactly one engine-owned terminal decision.
154#[derive(Clone, Debug, Eq, PartialEq)]
155pub enum DescribeStreamsGroupOutcome {
156    /// Kafka returned one exact streams-group description.
157    Described(DescribeStreamsGroupResult),
158    /// Kafka rejected the group-level operation.
159    BrokerRejected(DescribeStreamsGroupBrokerError),
160    /// Every requested group settled in exact caller order.
161    Batch(DescribeStreamsGroupsBatch),
162    /// Execution failed outside an exact Kafka rejection.
163    Failed(DescribeStreamsGroupFailure),
164}
165
166/// Failure to observe one named completion.
167#[derive(Clone, Copy, Debug, Eq, PartialEq)]
168pub enum DescribeStreamsGroupObserverError {
169    /// This linear observer already consumed its terminal.
170    AlreadyObserved,
171    /// The observer generation is no longer live.
172    Stale,
173}
174
175impl fmt::Display for DescribeStreamsGroupObserverError {
176    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
177        formatter.write_str(match self {
178            Self::AlreadyObserved => "Admin DescribeStreamsGroup result was already observed",
179            Self::Stale => "Admin DescribeStreamsGroup observer is stale",
180        })
181    }
182}
183
184impl std::error::Error for DescribeStreamsGroupObserverError {}