#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ManagedRole<R> {
role: R,
}
impl<R> ManagedRole<R> {
pub const fn new(role: R) -> Self {
Self { role }
}
pub const fn role(&self) -> &R {
&self.role
}
pub fn replace_role(&mut self, role: R) -> R {
std::mem::replace(&mut self.role, role)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StrongEdgeMutationError {
Allocation(EdgeAllocationError),
UnknownEdge(EdgeId),
WrongKind {
edge: EdgeId,
actual: EdgeKind,
},
TargetChanged {
expected: ManagedId,
actual: ManagedId,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WeakEdgeMutationError {
Allocation(EdgeAllocationError),
UnknownEdge(EdgeId),
WrongKind {
edge: EdgeId,
actual: EdgeKind,
},
TargetChanged {
expected: ManagedId,
actual: ManagedId,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum EphemeronMutationError {
Allocation(EdgeAllocationError),
UnknownEdge(EdgeId),
WrongKind {
edge: EdgeId,
actual: EdgeKind,
},
EntryChanged {
expected_key: ManagedId,
expected_value: ManagedId,
actual_key: ManagedId,
actual_value: ManagedId,
},
}
impl fmt::Display for EphemeronMutationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Allocation(error) => error.fmt(f),
Self::UnknownEdge(edge) => write!(f, "unknown ephemeron edge {}", edge.0),
Self::WrongKind { edge, actual } => {
write!(f, "edge {} is {actual:?}, not Ephemeron", edge.0)
}
Self::EntryChanged {
expected_key,
expected_value,
actual_key,
actual_value,
} => write!(
f,
"ephemeron entry changed from ({}, {}) to ({}, {})",
expected_key.allocation_ordinal(),
expected_value.allocation_ordinal(),
actual_key.allocation_ordinal(),
actual_value.allocation_ordinal()
),
}
}
}
impl Error for EphemeronMutationError {}
impl From<EdgeAllocationError> for EphemeronMutationError {
fn from(error: EdgeAllocationError) -> Self {
Self::Allocation(error)
}
}
impl fmt::Display for WeakEdgeMutationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Allocation(error) => error.fmt(f),
Self::UnknownEdge(edge) => write!(f, "unknown weak edge {}", edge.0),
Self::WrongKind { edge, actual } => {
write!(f, "edge {} is {actual:?}, not Weak", edge.0)
}
Self::TargetChanged { expected, actual } => write!(
f,
"weak edge target changed from allocation {} to allocation {}",
expected.allocation_ordinal(),
actual.allocation_ordinal()
),
}
}
}
impl Error for WeakEdgeMutationError {}
impl From<EdgeAllocationError> for WeakEdgeMutationError {
fn from(error: EdgeAllocationError) -> Self {
Self::Allocation(error)
}
}
impl fmt::Display for StrongEdgeMutationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Allocation(error) => error.fmt(f),
Self::UnknownEdge(edge) => write!(f, "unknown strong edge {}", edge.0),
Self::WrongKind { edge, actual } => {
write!(f, "edge {} is {actual:?}, not Strong", edge.0)
}
Self::TargetChanged { expected, actual } => write!(
f,
"strong edge target changed from allocation {} to allocation {}",
expected.allocation_ordinal(),
actual.allocation_ordinal()
),
}
}
}
impl Error for StrongEdgeMutationError {}
impl From<EdgeAllocationError> for StrongEdgeMutationError {
fn from(error: EdgeAllocationError) -> Self {
Self::Allocation(error)
}
}