Skip to main content

kafka_client_engine/admin/describe_features/
outcome.rs

1//! Stable generated-free terminals for Admin `DescribeFeatures`.
2
3use core::fmt;
4
5use super::DescribeFeaturesDescription;
6
7mod translate;
8
9pub(crate) use translate::translate_terminal;
10
11/// Stable delivery certainty independent of core and driver types.
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub enum DescribeFeaturesDeliveryStatus {
14    /// The failed call did not reach Kafka.
15    NotSent,
16    /// The failed call may have reached Kafka.
17    PossiblySent,
18}
19
20/// Exact signed top-level Kafka rejection and its throttle observation.
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22pub struct DescribeFeaturesBrokerError {
23    pub(super) throttle_time_ms: u32,
24    pub(super) code: i16,
25}
26
27impl DescribeFeaturesBrokerError {
28    /// Returns Kafka's nonnegative throttle observation.
29    pub const fn throttle_time_ms(self) -> u32 {
30        self.throttle_time_ms
31    }
32
33    /// Returns Kafka's exact signed nonzero error code.
34    pub const fn code(self) -> i16 {
35        self.code
36    }
37
38    /// Consumes the rejection into exact scalar parts.
39    pub const fn into_parts(self) -> (u32, i16) {
40        (self.throttle_time_ms, self.code)
41    }
42}
43
44/// Stable whole-operation failure category.
45#[derive(Clone, Copy, Debug, Eq, PartialEq)]
46pub enum DescribeFeaturesFailureKind {
47    /// The original public absolute deadline elapsed.
48    DeadlineElapsed,
49    /// Driver admission rejected the prepared request.
50    DriverRejected,
51    /// Driver-owned transport execution failed.
52    Transport,
53    /// Valid response facts exceeded admitted retained capacity.
54    ResponseTooLarge,
55    /// The selected API version cannot represent required semantics.
56    Compatibility,
57    /// A response was malformed or could not be normalized.
58    InvalidResponse,
59}
60
61/// Whole-operation failure with authoritative delivery certainty.
62#[derive(Clone, Copy, Debug, Eq, PartialEq)]
63pub struct DescribeFeaturesFailure {
64    pub(super) kind: DescribeFeaturesFailureKind,
65    pub(super) delivery: DescribeFeaturesDeliveryStatus,
66}
67
68impl DescribeFeaturesFailure {
69    /// Returns the stable failure category.
70    pub const fn kind(self) -> DescribeFeaturesFailureKind {
71        self.kind
72    }
73
74    /// Returns authoritative delivery certainty.
75    pub const fn delivery(self) -> DescribeFeaturesDeliveryStatus {
76        self.delivery
77    }
78}
79
80/// Exactly one engine-owned terminal decision.
81#[derive(Clone, Debug, Eq, PartialEq)]
82pub enum DescribeFeaturesOutcome {
83    /// Kafka returned bounded canonical feature metadata.
84    Described(DescribeFeaturesDescription),
85    /// Kafka rejected the request with an exact top-level error.
86    BrokerRejected(DescribeFeaturesBrokerError),
87    /// Execution failed outside an exact Kafka rejection.
88    Failed(DescribeFeaturesFailure),
89}
90
91/// Failure to observe one named completion.
92#[derive(Clone, Copy, Debug, Eq, PartialEq)]
93pub enum DescribeFeaturesObserverError {
94    /// This linear observer already consumed its terminal.
95    AlreadyObserved,
96    /// The observer generation is no longer live.
97    Stale,
98}
99
100impl fmt::Display for DescribeFeaturesObserverError {
101    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
102        formatter.write_str(match self {
103            Self::AlreadyObserved => "Admin DescribeFeatures result was already observed",
104            Self::Stale => "Admin DescribeFeatures observer is stale",
105        })
106    }
107}
108
109impl std::error::Error for DescribeFeaturesObserverError {}