Skip to main content

kafka_client_engine/admin/describe_user_scram_credentials/
outcome.rs

1//! Stable non-secret engine terminals for Admin `DescribeUserScramCredentials`.
2
3use core::fmt;
4
5mod translate;
6
7pub(crate) use translate::translate_terminal;
8
9/// Stable delivery certainty independent of core and driver types.
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum DescribeUserScramCredentialsDeliveryStatus {
12    /// The failed call did not reach Kafka.
13    NotSent,
14    /// The failed call may have reached Kafka.
15    PossiblySent,
16}
17
18/// One exact SCRAM mechanism code and positive iteration count.
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
20pub struct DescribeUserScramCredentialInfo {
21    pub(super) mechanism: i8,
22    pub(super) iterations: u32,
23}
24
25impl DescribeUserScramCredentialInfo {
26    /// Returns Kafka's exact signed SCRAM mechanism code.
27    pub const fn mechanism(self) -> i8 {
28        self.mechanism
29    }
30
31    /// Returns Kafka's positive iteration count.
32    pub const fn iterations(self) -> u32 {
33        self.iterations
34    }
35
36    /// Consumes this metadata into exact scalar parts.
37    pub const fn into_parts(self) -> (i8, u32) {
38        (self.mechanism, self.iterations)
39    }
40}
41
42/// Exact Kafka rejection and bounded nullable diagnostic.
43#[derive(Clone, Debug, Eq, PartialEq)]
44pub struct DescribeUserScramCredentialsBrokerError {
45    pub(super) code: i16,
46    pub(super) message: Option<String>,
47    pub(super) message_truncated: bool,
48}
49
50impl DescribeUserScramCredentialsBrokerError {
51    /// Returns Kafka's exact signed error code.
52    pub const fn code(&self) -> i16 {
53        self.code
54    }
55
56    /// Returns Kafka's nullable UTF-8-safe diagnostic prefix.
57    pub fn message(&self) -> Option<&str> {
58        self.message.as_deref()
59    }
60
61    /// Reports whether a present diagnostic was truncated.
62    pub const fn message_truncated(&self) -> bool {
63        self.message_truncated
64    }
65
66    /// Consumes the rejection into exact diagnostic parts.
67    pub fn into_parts(self) -> (i16, Option<String>, bool) {
68        (self.code, self.message, self.message_truncated)
69    }
70}
71
72/// Exact result Kafka returned for one correlated user.
73#[derive(Clone, Debug, Eq, PartialEq)]
74pub enum DescribeUserScramCredentialsUserResult {
75    /// Kafka returned non-secret mechanism and iteration metadata.
76    Described(Vec<DescribeUserScramCredentialInfo>),
77    /// Kafka rejected this user with an exact signed code.
78    BrokerFailed(DescribeUserScramCredentialsBrokerError),
79}
80
81/// One deterministic user result.
82#[derive(Clone, Debug, Eq, PartialEq)]
83pub struct DescribeUserScramCredentialOutcome {
84    pub(super) user: String,
85    pub(super) result: DescribeUserScramCredentialsUserResult,
86}
87
88impl DescribeUserScramCredentialOutcome {
89    /// Returns the correlated user identity.
90    pub fn user(&self) -> &str {
91        &self.user
92    }
93
94    /// Returns this user's exact result.
95    pub const fn result(&self) -> &DescribeUserScramCredentialsUserResult {
96        &self.result
97    }
98
99    /// Consumes this outcome into stable user and result parts.
100    pub fn into_parts(self) -> (String, DescribeUserScramCredentialsUserResult) {
101        (self.user, self.result)
102    }
103}
104
105/// Deterministically ordered per-user results plus Kafka's throttle observation.
106#[derive(Clone, Debug, Eq, PartialEq)]
107pub struct DescribeUserScramCredentialsBatch {
108    pub(super) throttle_time_ms: u32,
109    pub(super) outcomes: Vec<DescribeUserScramCredentialOutcome>,
110}
111
112impl DescribeUserScramCredentialsBatch {
113    /// Returns Kafka's nonnegative throttle observation.
114    pub const fn throttle_time_ms(&self) -> u32 {
115        self.throttle_time_ms
116    }
117
118    /// Returns explicit-filter caller order or all-user byte order.
119    pub fn outcomes(&self) -> &[DescribeUserScramCredentialOutcome] {
120        &self.outcomes
121    }
122
123    /// Consumes throttle and deterministically ordered per-user results.
124    pub fn into_parts(self) -> (u32, Vec<DescribeUserScramCredentialOutcome>) {
125        (self.throttle_time_ms, self.outcomes)
126    }
127}
128
129/// Stable whole-operation failure category.
130#[derive(Clone, Debug, Eq, PartialEq)]
131pub enum DescribeUserScramCredentialsFailureKind {
132    /// The original absolute deadline elapsed.
133    DeadlineElapsed,
134    /// Driver admission rejected the prepared request.
135    DriverRejected,
136    /// Driver-owned transport execution failed.
137    Transport,
138    /// Kafka rejected the complete query with an exact top-level error.
139    Broker(DescribeUserScramCredentialsBrokerError),
140    /// A valid response exceeded the admitted retained envelope.
141    ResponseTooLarge,
142    /// The selected API version cannot represent required semantics.
143    Compatibility,
144    /// A response was malformed or could not be correlated.
145    InvalidResponse,
146}
147
148/// Whole-operation failure with authoritative delivery certainty.
149#[derive(Clone, Debug, Eq, PartialEq)]
150pub struct DescribeUserScramCredentialsFailure {
151    pub(super) kind: DescribeUserScramCredentialsFailureKind,
152    pub(super) delivery: DescribeUserScramCredentialsDeliveryStatus,
153}
154
155impl DescribeUserScramCredentialsFailure {
156    /// Returns the stable failure category.
157    pub const fn kind(&self) -> &DescribeUserScramCredentialsFailureKind {
158        &self.kind
159    }
160
161    /// Returns authoritative delivery certainty.
162    pub const fn delivery(&self) -> DescribeUserScramCredentialsDeliveryStatus {
163        self.delivery
164    }
165}
166
167/// Exactly one engine-owned terminal decision.
168#[derive(Clone, Debug, Eq, PartialEq)]
169pub enum DescribeUserScramCredentialsOutcome {
170    /// Kafka returned zero or more deterministic non-secret user results.
171    Described(DescribeUserScramCredentialsBatch),
172    /// The operation failed outside a valid user-result set.
173    Failed(DescribeUserScramCredentialsFailure),
174}
175
176/// Failure to observe a named completion.
177#[derive(Clone, Copy, Debug, Eq, PartialEq)]
178pub enum DescribeUserScramCredentialsObserverError {
179    /// This linear observer already consumed its terminal.
180    AlreadyObserved,
181    /// The observer generation is no longer live.
182    Stale,
183}
184
185impl fmt::Display for DescribeUserScramCredentialsObserverError {
186    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
187        formatter.write_str(match self {
188            Self::AlreadyObserved => {
189                "Admin DescribeUserScramCredentials result was already observed"
190            }
191            Self::Stale => "Admin DescribeUserScramCredentials observer is stale",
192        })
193    }
194}
195
196impl std::error::Error for DescribeUserScramCredentialsObserverError {}