Use Magnus macros to implement TypedData trait#159
Merged
jbourassa merged 1 commit intobytecodealliance:mainfrom Mar 29, 2023
Merged
Use Magnus macros to implement TypedData trait#159jbourassa merged 1 commit intobytecodealliance:mainfrom
jbourassa merged 1 commit intobytecodealliance:mainfrom
Conversation
a5cc6af to
714ed65
Compare
Collaborator
|
This looks great, thank you @matsadler. I think a |
Magnus doesn't usually allow deriving TypedData for types with generics as the derived implementation isn't guaranteed to be correct. The implementations here are near identical to what would be derived, so use the new 'unsafe_generics' attribute to bypass the usual error.
714ed65 to
afe01d6
Compare
jbourassa
approved these changes
Mar 29, 2023
Collaborator
jbourassa
left a comment
There was a problem hiding this comment.
This looks great, thank you @matsadler.
+1, fantastic!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This library is a great stress test for Magnus' API, so I've been trying out some Magnus API changes to see how they fair in use.
While I was doing that I noticed there's a lot of implementations of
TypedDatathat are near identical to what would be derived.Magnus doesn't usually allow deriving
TypedDatafor types with generics as the derived implementation isn't guaranteed to be correct, and I don't want people trying it, find it compiles, and then hit nasty segfaults.However, it seems mean to make you write out exactly what the macro would produce, so I added an
unsafe_genericsattribute to bypass the error, and I've back ported it to the current release branch of the magnus-macros crate.The changes here remove the
TypedDataimplementations in favour of the macros with theunsafe_genericsattribute set.