Skip to content

Commit

Permalink
Derive Deref for Sealed<T> (#759)
Browse files Browse the repository at this point in the history
Derive Deref for Sealed<T>
  • Loading branch information
emhane authored Oct 4, 2024
1 parent fb47220 commit 038c464
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ derive_more = { workspace = true, features = [
"into",
"into_iterator",
"display",
"deref",
] }
paste.workspace = true

Expand Down
13 changes: 4 additions & 9 deletions crates/primitives/src/sealed.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
use derive_more::Deref;

use crate::B256;

/// A consensus hashable item, with its memoized hash.
///
/// We do not implement any specific hashing algorithm here. Instead types
/// implement the [`Sealable`] trait to provide define their own hash.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deref)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Sealed<T> {
/// The inner item
#[deref]
inner: T,
/// Its hash.
seal: B256,
}

impl<T> core::ops::Deref for Sealed<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.inner()
}
}

impl<T> Sealed<T> {
/// Instantiate without performing the hash. This should be used carefully.
pub const fn new_unchecked(inner: T, seal: B256) -> Self {
Expand Down

0 comments on commit 038c464

Please sign in to comment.