anchor-gen is a handy crate which allows the generation of a CPI crates from only a program's Anchor IDL.
It generates all the necessary Rust structs/functions/impls to allow CPI invocation of the target program.
While trying to use it for my own IDL (minimal example pasted below) I encountered errors from Borsh, complaining about the Default
trait not being implemented on [u128, 172]
. This makes sense as the Default
trait is only implemented on a finite set of sizes (0 to 32), which is why I had to implement the Default
trait for MyStruct
manually in the program crate. However the IDL does not know about that.
I tried to add that Default
implementation for MyStruct
in the CPI crate, but to no avail since it clashes with the auto-generated one.
Question: Is there a way to override that Default
auto-gen implementation? (I will take other workarounds as well if there are)
Reference IDL:
{
"version": "0.1.0",
"name": "my_program",
"instructions": [
{
"name": "initMyStruct",
"accounts": [
{
"name": "myStruct",
"isMut": true,
"isSigner": false
}
],
"args": []
}
],
"accounts": [
{
"name": "MyStruct",
"type": {
"kind": "struct",
"fields": [
{
"name": "isMosturized",
"type": "bool"
},
{
"name": "reservedSpace",
"type": {
"array": [
"u128",
172
]
}
}
]
}
}
]
}