use alloc::boxed::Box;
use crate::{digest::Digest, loose_commit::LooseCommit};
pub const MAX_STRATA_DEPTH: Depth = Depth(2);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Depth(pub u32);
impl core::fmt::Display for Depth {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Depth({})", self.0)
}
}
pub trait DepthMetric {
fn to_depth(&self, digest: Digest<LooseCommit>) -> Depth;
}
impl<Digestish: From<Digest<LooseCommit>>, Depthish: Into<Depth>> DepthMetric
for fn(Digestish) -> Depthish
{
fn to_depth(&self, digest: Digest<LooseCommit>) -> Depth {
self(Digestish::from(digest)).into()
}
}
impl<T: DepthMetric> DepthMetric for Box<T> {
fn to_depth(&self, digest: Digest<LooseCommit>) -> Depth {
T::to_depth(self, digest)
}
}