use super::{GroupConsumerHandle, GroupConsumerPortDormantReleaseError};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum GroupConsumerDormantReleaseErrorKind {
Closed,
GroupUnavailable,
NotDormant,
Internal,
}
#[must_use = "release rejection retains the exact registered group handle"]
pub struct GroupConsumerDormantReleaseError {
kind: GroupConsumerDormantReleaseErrorKind,
handle: GroupConsumerHandle,
}
impl GroupConsumerDormantReleaseError {
pub const fn kind(&self) -> GroupConsumerDormantReleaseErrorKind {
self.kind
}
pub fn into_handle(self) -> GroupConsumerHandle {
self.handle
}
}
impl core::fmt::Debug for GroupConsumerDormantReleaseError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter
.debug_struct("GroupConsumerDormantReleaseError")
.field("kind", &self.kind)
.field("handle", &self.handle)
.finish()
}
}
impl core::fmt::Display for GroupConsumerDormantReleaseError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
formatter,
"dormant group-consumer release failed: {:?}",
self.kind
)
}
}
impl std::error::Error for GroupConsumerDormantReleaseError {}
impl GroupConsumerHandle {
pub fn release_dormant(self) -> Result<(), GroupConsumerDormantReleaseError> {
match self.port.release_dormant_registration(self.group_id) {
Ok(()) => Ok(()),
Err(error) => {
let kind = match error {
GroupConsumerPortDormantReleaseError::Closed => {
GroupConsumerDormantReleaseErrorKind::Closed
}
GroupConsumerPortDormantReleaseError::UnknownGroup => {
GroupConsumerDormantReleaseErrorKind::GroupUnavailable
}
GroupConsumerPortDormantReleaseError::NotDormant => {
GroupConsumerDormantReleaseErrorKind::NotDormant
}
GroupConsumerPortDormantReleaseError::Contended
| GroupConsumerPortDormantReleaseError::InternalInvariant => {
GroupConsumerDormantReleaseErrorKind::Internal
}
};
Err(GroupConsumerDormantReleaseError { kind, handle: self })
}
}
}
}