Macro data

Source
macro_rules! data {
    ($name:ident, $doc:expr) => { ... };
}
Expand description

Creates a new type wrapping a variable-size byte array with common methods and trait implementations.

The data! macro generates a new type that wraps a Data container, automatically implementing common methods and traits. This provides a convenient way to create domain-specific types for variable-length binary data with minimal boilerplate.

§Usage

// Define a type for variable-length script data
data!(ScriptData, "A variable-length script for Zcash transactions.");

// Use the generated type
let script = ScriptData::new(vec![0xAA, 0xBB, 0xCC]);

§Generated Functionality

The generated type includes methods for creation, conversion, and inspection, as well as implementations for common traits like Parse, Debug, Clone, and various conversion traits to and from byte collections.

This macro is especially useful for creating strong types around Zcash protocol elements that have variable lengths, such as encrypted memos, scripts, and other dynamically-sized data.