kafka_client_engine/transaction/initialization/
control_error.rs1use core::fmt;
4
5use super::TransactionToken;
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum TransactionControlErrorKind {
10 InvalidDeadline,
12 Contended,
14 Closed,
16 StaleOwner,
18 AlreadyActive,
20 NotActive,
22 StaleTransaction,
24 OutstandingOperations,
26 AbortRequired,
28 EndInProgress,
30 Fenced,
32 Backpressure,
34 IdentityExhausted,
36 HostUnavailable,
38}
39
40#[derive(Clone, Copy, Debug, Eq, PartialEq)]
42pub struct TransactionControlError {
43 kind: TransactionControlErrorKind,
44}
45
46impl TransactionControlError {
47 pub(super) const fn new(kind: TransactionControlErrorKind) -> Self {
48 Self { kind }
49 }
50
51 pub const fn kind(self) -> TransactionControlErrorKind {
53 self.kind
54 }
55}
56
57impl fmt::Display for TransactionControlError {
58 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
59 write!(formatter, "transaction control rejected: {:?}", self.kind)
60 }
61}
62
63impl std::error::Error for TransactionControlError {}
64
65#[must_use = "transaction end rejection retains the active transaction token"]
67pub struct TransactionEndAdmissionError<'owner> {
68 kind: TransactionControlErrorKind,
69 transaction: TransactionToken<'owner>,
70}
71
72impl<'owner> TransactionEndAdmissionError<'owner> {
73 pub(super) const fn new(
74 kind: TransactionControlErrorKind,
75 transaction: TransactionToken<'owner>,
76 ) -> Self {
77 Self { kind, transaction }
78 }
79
80 pub const fn kind(&self) -> TransactionControlErrorKind {
82 self.kind
83 }
84
85 pub fn into_transaction(self) -> TransactionToken<'owner> {
87 self.transaction
88 }
89}
90
91impl fmt::Debug for TransactionEndAdmissionError<'_> {
92 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
93 formatter
94 .debug_struct("TransactionEndAdmissionError")
95 .field("kind", &self.kind)
96 .finish_non_exhaustive()
97 }
98}
99
100impl fmt::Display for TransactionEndAdmissionError<'_> {
101 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
102 write!(formatter, "transaction end rejected: {:?}", self.kind)
103 }
104}
105
106impl std::error::Error for TransactionEndAdmissionError<'_> {}