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

versionize: rework of the from/into/convert feature to allow conversion with generics #1633

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nsarlin-zama
Copy link
Contributor

@nsarlin-zama nsarlin-zama commented Oct 4, 2024

closes: https://github.com/zama-ai/tfhe-rs-internal/issues/748

PR content/description

The Versionize proc macro accepts some arguments that will affect the implementation of the traits. From example, the #[versionize(SerializableMyTypeVersions, from = SerializableMyType, into = SerializableMyType)] will apply a conversion method before the versioning, like serde does: https://serde.rs/container-attrs.html#from. However before this PR, this parameter did not work if the conversion type had generics, or if the conversion method needed specific bounds.

On a side note, the syntax was a bit updated. The from/try_from/into keywords were used to mimic serde, for user convenience. However in Versionize we actually don't support having a different value for from and into. This is now checked during the argument parsing. New shortcut arguments have also been added: convert/try_convert. They work the same way except that you only need one argument: #[versionize(SerializableMyTypeVersions, convert = SerializableMyType)].

On the same topic, before this pr the attribute required the to state the name of the dispatch enum in that case: #[versionize(SerializableMyTypeVersions, from = SerializableMyType, into = SerializableMyType)]. This is now automatically detected when we use a conversion, which means that the attribute can be simplified as #[versionize(convert = SerializableMyType)]

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

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

Successfully merging this pull request may close these issues.

1 participant