miden-protocol-macros 0.14.5

Procedural macros for Miden protocol
Documentation
# miden-protocol-macros

A collection of procedural macros for the Miden protocol.

## WordWrapper

The `WordWrapper` derive macro automatically implements helpful accessor methods and conversions for tuple structs that wrap a `Word` type.

### Usage

Add the derive macro to any tuple struct with a single `Word` field:

```rust
use miden_protocol_macros::WordWrapper;
use miden_crypto::word::Word;

#[derive(WordWrapper)]
pub struct NoteId(Word);
```

### Generated Methods

The macro automatically generates the following methods:

#### Accessor Methods

- **`new_unchecked(Word) -> Self`** - Construct without any checks
- **`as_elements(&self) -> &[Felt]`** - Returns the elements representation of the wrapped Word
- **`as_bytes(&self) -> [u8; 32]`** - Returns the byte representation
- **`to_hex(&self) -> String`** - Returns a big-endian, hex-encoded string
- **`as_word(&self) -> Word`** - Returns the underlying Word value

### Example

```rust
use miden_protocol_macros::WordWrapper;
use miden_crypto::word::Word;

#[derive(Debug, Clone, Copy, PartialEq, Eq, WordWrapper)]
pub struct NoteId(Word);

// Create using new_unchecked (generated by the macro)
let word = Word::from([Felt::ONE, Felt::ZERO, Felt::ONE, Felt::ZERO]);
let note_id = NoteId::from_raw(word);

// Use accessor methods
let elements = note_id.as_elements();
let bytes = note_id.as_bytes();
let hex = note_id.to_hex();
let word_back = note_id.as_word();
```

### Requirements

The macro can only be applied to:
- Tuple structs (e.g., `struct Foo(Word)`)
- With exactly one field
- Where that field is of type `Word`

### Benefits

Using this macro eliminates boilerplate code. Instead of manually writing ~50 lines of implementation code for each Word wrapper type, you can simply add `#[derive(WordWrapper)]` to your struct definition.

This is particularly useful in the Miden codebase where many types like `NoteId`, `TransactionId`, `Nullifier`, `BatchId`, etc. all follow the same pattern of wrapping a `Word` and providing similar accessor methods.

### Important Notes

- The macro generates the `new_unchecked` constructor. You should not manually implement this method.
- Previously, the macro also generated `From<T>` and `From<&T>` trait implementations for `Word` and `[u8; 32]`. These have been **removed** to give types more control over their conversions. If you need these conversions, implement them manually for your specific type.