versionize: rework of the from/into/convert feature to allow conversion with generics #1633
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: