Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive Deref for Sealed<T> #759

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading