feat: store::Error implements std::error::Error

This commit is contained in:
Jeremy Wall 2024-07-04 10:20:09 -05:00
parent 57953e1861
commit f949ee7dac

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
//! The [Merkle Dag](crate::dag::Merkle) backing store trait. //! 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}; use crate::{hash::HashWriter, node::Node};
@ -25,6 +25,25 @@ pub enum StoreError {
NoSuchDependents, 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)] #[allow(async_fn_in_trait)]
/// Trait representing the backing storage interface for a [Merkle DAG](crate::dag::Merkle). /// Trait representing the backing storage interface for a [Merkle DAG](crate::dag::Merkle).
pub trait AsyncStore<HW> pub trait AsyncStore<HW>