saber-hq / anchor-gen

Generates an Anchor CPI crate from a JSON IDL.

Home Page:https://crates.io/crates/anchor-gen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Default trait on user-defined IDL structs

losman0s opened this issue · comments

commented

Is there a way to handle custom Default trait definition for some of the Defined structs, e.g.:

{
  "name": "MyStruct",
  "type": {
    "kind": "struct",
    "fields": [
      {
        "name": "authority",
        "type": "publicKey"
      },
      {
        "name": "reservedSpace",
        "type": {
          "array": ["u128", 256]
        }
      }
    ]
  }
}

atm the explicit sizes (0-32) in the standard implementation prevents generation:
the trait 'Default' is not implemented for '[u128; 256]'

commented

Not sure if notifications go through so will try pinging @macalinao

This specific case is fixed. We should probably add a way to explicitly specify that a Default should not be generated for a type though

commented

This specific case is fixed. We should probably add a way to explicitly specify that a Default should not be generated for a type though

Great thanks! One last clarification though: I don't get the use case for the separation between anchor_gen::generate_cpi_crate and anchor_gen::generate_cpi_interface. The former, shown in the README, seems to only be a "forced defaults" of the latter.

  1. Am I missing something
  2. If not, it might be valuable to avoid confusion by either explaining the distinction, or using anchor_gen::generate_cpi_interface in teh README (although I agree examples are pretty helpful in any case)

Backwards compatibility. Maybe we should mark the other one as deprecated