ShankType

Derive Macro ShankType 

Source
#[derive(ShankType)]
{
    // Attributes available to this derive:
    #[idl_name]
    #[idl_type]
    #[skip]
    #[pod_sentinel]
}
Expand description

Annotates a struct or enum that shank will consider a type containing de/serializable data.

The macro does not generate any code. The annotation is used to indicate to shank-idl that the the type should be included in the program’s IDL.

§Example

use shank::ShankType;

#[derive(ShankType)]
pub struct Metadata {
    pub update_authority: Pubkey,
    pub mint: Pubkey,
    pub primary_sale_happened: bool,
}

§Type Attributes

§#[pod_sentinel(...)] attribute

Specifies the sentinel value for custom types used with PodOption. This is required when your type is wrapped in PodOption<T> for fixed-size optional serialization (bytemuck/podded).

The sentinel value is a comma-separated list of u8 decimal integers (0-255) that represents the “None” state for this type.

use shank::ShankType;

#[derive(ShankType)]
#[pod_sentinel(255, 255, 255, 255)]
pub struct CustomU32Wrapper {
    pub value: u32,
}

// Now this type can be used with PodOption:
#[derive(ShankAccount)]
pub struct MyAccount {
    pub optional_field: PodOption<CustomU32Wrapper>,
}

§Note

The fields of a ShankType struct or enum can reference other types as long as they are annotated with ShankType, BorshSerialize or BorshDeserialize.