Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip_deserializing required even when not deriving Decode #12

Open
realbigsean opened this issue Oct 12, 2023 · 0 comments
Open

skip_deserializing required even when not deriving Decode #12

realbigsean opened this issue Oct 12, 2023 · 0 comments

Comments

@realbigsean
Copy link
Member

If you try to derive just Encode on a struct, using transparent, you are required to add skip_deserializing to all but one struct field, even if you aren't deriving Decode.

Example:

#[derive(Debug, Clone, PartialEq, Encode)]
#[ssz(struct_behaviour = "transparent")]
pub struct RuntimeVariableList<T: Encode> {
    vec: Vec<T>,
    #[ssz(skip_serializing)]
    max_len: usize,
}

The above results in:

error: proc-macro derive panicked
   --> beacon_node/lighthouse_network/src/rpc/methods.rs:346:35
    |
346 | #[derive(Debug, Clone, PartialEq, Encode)]
    |                                   ^^^^^^
    |
    = help: message: A "transparent" struct must have exactly one non-skipped field (2 fields found)

error: could not compile `lighthouse_network` (lib) due to previous error

Whereas the following compiles fine:

#[derive(Debug, Clone, PartialEq, Encode)]
#[ssz(struct_behaviour = "transparent")]
pub struct RuntimeVariableList<T: Encode> {
    vec: Vec<T>,
    #[ssz(skip_serializing, skip_deserializing)]
    max_len: usize,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant