#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
pub enum CollectionError {
#[error("{0}")]
Codec(#[from] crate::storable::CodecError),
#[error("invalid collection: {0}")]
Corrupt(&'static str),
#[error("unrecognized collection format")]
Format,
#[error("collection checksum mismatch")]
Checksum,
#[error("collection resource budget exceeded")]
Budget,
#[error("collection growth refused")]
Growth,
#[error("collection memory is not empty")]
NotEmpty,
#[error("collection owner is poisoned")]
Poisoned,
#[error("invalid collection index or range")]
Bounds,
#[error("collection Wire record: {0}")]
Wire(#[from] ic_wire::Error),
#[error("{0}")]
Cell(#[from] crate::StableCellPayloadError),
}
pub(super) type Result<T> = std::result::Result<T, CollectionError>;
pub(super) fn ensure(condition: bool, error: CollectionError) -> Result<()> {
if condition { Ok(()) } else { Err(error) }
}