#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Multicodec(#[from] multi_codec::Error),
#[error(transparent)]
Multihash(#[from] multi_hash::Error),
#[error(transparent)]
Cid(#[from] CidError),
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum CidError {
#[error("Missing target data encoding codec")]
MissingTargetCodec,
#[error("Missing hash data")]
MissingHash,
#[error("Building legacy Cid with the wrong function")]
LegacyCid,
#[error("Building modern Cid with the wrong function")]
ModernCid,
}
impl Error {
#[must_use]
pub const fn kind(&self) -> &str {
match self {
Self::Multicodec(_) => "Multicodec",
Self::Multihash(_) => "Multihash",
Self::Cid(_) => "Cid",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_kind() {
let err = Error::Cid(CidError::MissingHash);
assert_eq!(err.kind(), "Cid");
}
#[test]
fn test_error_send_sync() {
fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
assert_send::<Error>();
assert_sync::<Error>();
}
}