compacted_map_key.rs
Overview
This file defines the structure and associated data for the CompactedMapKey type, which is a key entity used to uniquely identify a mapping related to blocks and attestations within the system. It encapsulates three key pieces of information: a block sequence number, a block identifier, and an attestation target type. These components collectively represent the context needed to access or manage compacted data maps relevant to block attestations.
Struct: CompactedMapKey
Definition
pub struct CompactedMapKey {
block_seq_no: BlockSeqNo,
block_identifier: BlockIdentifier,
attestation_target_type: AttestationTargetType,
}
Purpose
CompactedMapKey serves as a composite key that uniquely identifies a compacted map entry by combining:
block_seq_no: The sequential number of the block.block_identifier: An identifier for the block, encapsulating further details.attestation_target_type: The type of attestation target associated with this block.
Derivations and Traits
The struct derives the following traits and macros:
Clone,Debug: For duplication and debugging purposes.Getters: Automatically generates getter methods for the fields.TypedBuilder: Provides a builder pattern for constructing instances safely and clearly.Eq,PartialEq,Ord,PartialOrd: Enables equality checks and ordering, allowing the struct to be used in sorted collections or for comparison operations.
Fields
Field Name | Type | Description |
|---|---|---|
|
| Numeric sequence of the block. |
|
| Unique identifier for the block. |
|
| Enum/type describing the kind of attestation target. |
Methods
The file uses the derive_getters::Getters macro, which generates the following getter methods automatically:
Method Name | Returns | Description |
|---|---|---|
|
| Returns the block sequence number. |
|
| Returns the block identifier. |
|
| Returns the attestation target type. |
Usage Example
use crate::types::{BlockIdentifier, BlockSeqNo};
use crate::node::associated_types::AttestationTargetType;
use compacted_map_key::CompactedMapKey;
let key = CompactedMapKey::builder()
.block_seq_no(BlockSeqNo::from(42))
.block_identifier(BlockIdentifier::new(/* params */))
.attestation_target_type(AttestationTargetType::SomeType)
.build();
println!("Block seq no: {:?}", key.block_seq_no());
Note: Construction uses the builder pattern provided by TypedBuilder, ensuring that all fields are set explicitly.
Implementation Details
The use of
TypedBuilderfacilitates the creation ofCompactedMapKeyinstances with compile-time checks, preventing incomplete initialization.Deriving ordering traits (
Ord,PartialOrd) implies that instances ofCompactedMapKeycan be sorted or used as keys in ordered containers, such asBTreeMap.The struct fields are private, enforcing encapsulation; access is provided via generated getter methods.
Interaction With Other Components
BlockSeqNoandBlockIdentifier: These types represent fundamental block metadata and are imported from thecrate::typesmodule. They likely provide more detailed functionality related to block identification and ordering.AttestationTargetType: Imported fromcrate::node::associated_types, it defines the category or type of attestation target, likely enumerating various valid attestation targets within the system.The
CompactedMapKeyis intended for use as a key in maps or data structures that store compacted attestation data, linking block metadata and attestation types in a unique composite key.
Diagram
classDiagram
class CompactedMapKey {
-block_seq_no: BlockSeqNo
-block_identifier: BlockIdentifier
-attestation_target_type: AttestationTargetType
+block_seq_no()
+block_identifier()
+attestation_target_type()
}
This diagram illustrates the encapsulated fields and the public getter methods of the CompactedMapKey struct, emphasizing its role as a data holder with controlled access.