pub(crate) const MISSING_LOCK_GUARD_ERROR: &str = "Missing lock guard";
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum TryReserveError {
CapacityOverflow,
AllocError {
layout: std::alloc::Layout,
},
}
impl std::fmt::Display for TryReserveError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("memory allocation failed because ")?;
let reason = match self {
TryReserveError::CapacityOverflow => {
"the computed capacity exceeded the collection's maximum"
}
TryReserveError::AllocError { .. } => "the memory allocator returned an error",
};
f.write_str(reason)
}
}
impl std::error::Error for TryReserveError {}
#[derive(Clone, PartialEq, Eq)]
pub enum TxResult<T> {
Completed(T),
RequirementNotMet(usize, String, T),
}
impl<T> std::fmt::Debug for TxResult<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Completed(state) => write!(f, "Transaction completed. Result: {:?}", state),
Self::RequirementNotMet(index, name, state) => {
write!(
f,
"Requirement at index [{}] not met: {}. State: {:?}",
index, name, state
)
}
}
}
}
impl<T> std::fmt::Display for TxResult<T>
where
T: std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Completed(state) => write!(f, "Transaction completed. Result: {}", state),
Self::RequirementNotMet(index, name, state) => {
write!(
f,
"Requirement at index [{}] not met: {}. State: {}",
index, name, state
)
}
}
}
}