Skip to content

Commit

Permalink
Derive Arbitrary for Sealed<T> (#762)
Browse files Browse the repository at this point in the history
* Derive arbitrary for Sealed<T>

* Manual impl Arbitrary for Sealed<T>

* Fix lint
  • Loading branch information
emhane authored Oct 4, 2024
1 parent 038c464 commit b222822
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/primitives/src/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::B256;
/// implement the [`Sealable`] trait to provide define their own hash.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deref)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))]
pub struct Sealed<T> {
/// The inner item
#[deref]
Expand Down Expand Up @@ -62,6 +63,16 @@ impl<T> Sealed<T> {
}
}

#[cfg(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 b222822

Please sign in to comment.