Skip to content

Commit

Permalink
Manual impl Arbitrary for Sealed<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Oct 4, 2024
1 parent 7556ceb commit 89f495c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/primitives/src/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::B256;
/// implement the [`Sealable`] trait to provide define their own hash.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))]
#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
pub struct Sealed<T> {
/// The inner item
inner: T,
Expand Down Expand Up @@ -68,6 +68,16 @@ impl<T> Sealed<T> {
}
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a, T> arbitrary::Arbitrary<'a> for Sealed<T>
where
T: for<'b> arbitrary::Arbitrary<'b> + Sealable,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(T::arbitrary(u)?.seal_slow())
}
}

/// Sealeable objects.
pub trait Sealable: Sized {
/// Calculate the seal hash, this may be slow.
Expand Down

0 comments on commit 89f495c

Please sign in to comment.