Derive Macro codegen::Block

source ·
#[derive(Block)]
{
    // Attributes available to this derive:
    #[substrate]
}
Expand description

Derives substrate::block::Block for a struct or enum.

You must specify the block’s IO by adding a #[substrate(io = "IoType")] attribute:

use serde::{Serialize, Deserialize};
use substrate::block::Block;

#[derive(Block, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)]
#[substrate(io = "substrate::io::TestbenchIo")]
pub struct MyBlock {
  // ...
}

This derive macro only works if you want to use the default value of the IO. If the IO type does not implement Default, or you want to use a non-default value, you must implement Block manually.

The ID value generated by this macro will have the form mycrate::mymodule::MyBlock. The block name function will return the name of the struct/enum converted to snake case. For example, the name of a block called MyBlock will be my_block. If you wish to customize this behavior, consider implementing Block manually.