alloy-rs / rlp

Fast implementation of Ethereum RLP serialization
Apache License 2.0
77 stars 16 forks source link

`#[rlp(..)]` does not allow multiple attributes #9

Open Wodann opened 6 months ago

Wodann commented 6 months ago

If you want to derive both RlpDecodable and RlpEncodable for a struct that has a field that needs to be omitted, it requires both the #[rlp(default)] (for decoding) and #[rlp(skip) (for encoding) attributes.

However, if you combine these two values into a single field annotation, the procedural macro is no longer able to detect the attributes correctly and raises an error. For example:

struct Foo {
  pub bar: u64,
  #[rlp(default, skip)]
  pub cache: OnceLock<u64>,
}

raises the compiler error the trait boundstd::sync::OnceLock: accesslist::::alloy_rlp::Decodableis not satisfied.

Instead writing:

struct Foo {
  pub bar: u64,
  #[rlp(default)]
  #[rlp(skip)]
  pub cache: OnceLock<u64>,
}

does compile successfully.