use kafka_client_core::AssignmentEpoch;
use super::{
assignment_error::assignment_error_kind,
result::{
AssignedConsumerAccepted, AssignedConsumerPortAcceptedFaultKind, AssignedConsumerPortError,
},
};
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct AssignedConsumerAssignmentEpoch(AssignmentEpoch);
impl AssignedConsumerAssignmentEpoch {
pub const fn get(self) -> u64 {
self.0.get()
}
pub(super) const fn from_core(epoch: AssignmentEpoch) -> Self {
Self(epoch)
}
pub(super) const fn into_core(self) -> AssignmentEpoch {
self.0
}
}
#[must_use = "assignment acceptance and wake diagnostics must be inspected"]
#[derive(Clone, Copy)]
pub struct AssignedConsumerTryReplaceAssignmentAccepted {
epoch: AssignedConsumerAssignmentEpoch,
fault: Option<super::AssignedConsumerAcceptedFaultKind>,
}
impl AssignedConsumerTryReplaceAssignmentAccepted {
pub const fn epoch(&self) -> AssignedConsumerAssignmentEpoch {
self.epoch
}
pub const fn fault(&self) -> Option<super::AssignedConsumerAcceptedFaultKind> {
self.fault
}
pub(super) fn from_port(accepted: AssignedConsumerAccepted<AssignmentEpoch>) -> Self {
let fault = accepted.fault().map(|fault| match fault {
AssignedConsumerPortAcceptedFaultKind::Wake => {
super::AssignedConsumerAcceptedFaultKind::Wake
}
});
Self {
epoch: AssignedConsumerAssignmentEpoch::from_core(accepted.into_value()),
fault,
}
}
}
impl std::fmt::Debug for AssignedConsumerTryReplaceAssignmentAccepted {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("AssignedConsumerTryReplaceAssignmentAccepted")
.field("epoch", &self.epoch)
.field("fault", &self.fault)
.finish()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AssignedConsumerTryReplaceAssignmentErrorKind {
Contended,
Closed,
Pending,
AssignmentCapacity,
TopicCapacity,
RetainedNameCapacity,
EventCapacity,
EmptyAssignment,
DuplicatePartition,
DeadlineOverflow,
ResourceExhausted,
HostUnavailable,
InternalInvariant,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AssignedConsumerTryReplaceAssignmentError {
kind: AssignedConsumerTryReplaceAssignmentErrorKind,
}
impl AssignedConsumerTryReplaceAssignmentError {
pub const fn kind(&self) -> AssignedConsumerTryReplaceAssignmentErrorKind {
self.kind
}
pub(super) const fn from_port(error: &AssignedConsumerPortError) -> Self {
Self {
kind: assignment_error_kind(error),
}
}
}
impl std::fmt::Display for AssignedConsumerTryReplaceAssignmentError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
formatter,
"assigned-consumer assignment replacement failed: {:?}",
self.kind
)
}
}
impl std::error::Error for AssignedConsumerTryReplaceAssignmentError {}