Skip to content

skip_deserializing required even when not deriving Decode #12

@realbigsean

Description

@realbigsean

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,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions