#[derive(WordWrapper)]Expand description
Generates accessor methods for tuple structs wrapping a Word type.
Automatically implements:
new_unchecked(Word) -> Self- Construct without further checksas_elements(&self) -> &[Felt]- Returns the elements representationas_bytes(&self) -> [u8; 32]- Returns the byte representationto_hex(&self) -> String- Returns a big-endian, hex-encoded stringas_word(&self) -> Word- Returns the underlying Word
Note: This macro does NOT generate From trait implementations. If you need conversions
to/from Word or [u8; 32], implement them manually for your type.
§Example
ⓘ
use miden_protocol_macros::WordWrapper;
use miden_crypto::word::Word;
#[derive(WordWrapper)]
pub struct NoteId(Word);This will generate implementations equivalent to:
ⓘ
impl NoteId {
/// Construct without further checks from a given `Word`
///
/// # Warning
///
/// This requires the caller to uphold the guarantees/invariants of this type (if any).
/// Check the type-level documentation for guarantees/invariants.
pub fn new_unchecked(word: Word) -> Self {
Self(word)
}
pub fn as_elements(&self) -> &[Felt] {
self.0.as_elements()
}
pub fn as_bytes(&self) -> [u8; 32] {
self.0.as_bytes()
}
pub fn to_hex(&self) -> String {
self.0.to_hex()
}
pub fn as_word(&self) -> Word {
self.0
}
}