Skip to content

Implement #[derive(Packable)] #11362

Closed

Description

@benesjan

For a lot of structs we need an implementation of both the Serialize, Deserialize and Packable traits but the implementation of Packable trait is equivalent to Serialize and Deserialize as those are already optimal serialization-size wise.

In those situation having an explicit implementation of Packable is a lot of boilerplate and hence it would be desirable to reduce that by having a #[derive(Packable)] macro that would generate:

impl<let MY_STRUCT_SERIALIZED_LENGTH: u32> Packable<MY_STRUCT_SERIALIZED_LENGTH> for MyStruct
{
    fn pack(self) -> [Field; MY_STRUCT_SERIALIZED_LENGTH] {
        self.serialize()
    }

    fn unpack(packed: [Field; MY_STRUCT_SERIALIZED_LENGTH]) -> Self {
        Self::deserialize(packed)
    }
}

Activity

  1. benesjan commented on Feb 17, 2025

    @benesjan
    ContributorAuthor

    Tackled in #11136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions