From f949ee7dac7c993c38e152b910e73342541442e6 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 4 Jul 2024 10:20:09 -0500 Subject: [PATCH] feat: store::Error implements std::error::Error --- src/store.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/store.rs b/src/store.rs index 290418e..caa2080 100644 --- a/src/store.rs +++ b/src/store.rs @@ -13,7 +13,7 @@ // limitations under the License. //! The [Merkle Dag](crate::dag::Merkle) backing store trait. -use std::collections::BTreeMap; +use std::{collections::BTreeMap, error::Error, fmt}; use crate::{hash::HashWriter, node::Node}; @@ -25,6 +25,25 @@ pub enum StoreError { NoSuchDependents, } +impl fmt::Display for StoreError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + StoreError::StoreFailure(msg) => write!(f, "{}", msg), + StoreError::NoSuchDependents => write!(f, "No such Dependents"), + } + } +} + +impl Error for StoreError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } + + fn cause(&self) -> Option<&dyn Error> { + self.source() + } +} + #[allow(async_fn_in_trait)] /// Trait representing the backing storage interface for a [Merkle DAG](crate::dag::Merkle). pub trait AsyncStore