#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum FastCasError<E> {
Abort {
current: usize,
error: E,
attempts: u32,
},
Conflict {
current: usize,
attempts: u32,
},
}
impl<E> FastCasError<E> {
#[inline]
pub const fn current(&self) -> usize {
match self {
Self::Abort { current, .. } | Self::Conflict { current, .. } => *current,
}
}
#[inline]
pub const fn attempts(&self) -> u32 {
match self {
Self::Abort { attempts, .. } | Self::Conflict { attempts, .. } => *attempts,
}
}
#[inline]
pub const fn is_abort(&self) -> bool {
matches!(self, Self::Abort { .. })
}
#[inline]
pub const fn is_conflict(&self) -> bool {
matches!(self, Self::Conflict { .. })
}
#[inline]
pub const fn error(&self) -> Option<&E> {
match self {
Self::Abort { error, .. } => Some(error),
Self::Conflict { .. } => None,
}
}
#[inline]
pub fn into_error(self) -> Option<E> {
match self {
Self::Abort { error, .. } => Some(error),
Self::Conflict { .. } => None,
}
}
}