feature: Add type_name override to Describe proc macro#1671
Merged
talekhinezh merged 2 commits intodevelopfrom Jan 8, 2024
Merged
feature: Add type_name override to Describe proc macro#1671talekhinezh merged 2 commits intodevelopfrom
talekhinezh merged 2 commits intodevelopfrom
Conversation
Benchmark for d7a020bClick to view benchmark
|
talekhinezh
approved these changes
Jan 8, 2024
dhedey
commented
Jan 15, 2024
| get_sbor_attribute_string_value(&attrs, "type_name")?.unwrap_or(ident.to_string()); | ||
|
|
||
| let type_id = quote! { | ||
| ::sbor::RustTypeId::novel_with_code( |
Contributor
Author
There was a problem hiding this comment.
Note for the future - we can consider just using core::any::TypeId::of::<Self> here, if we add where Self: 'static to the Describe trait (which should be fine) rust-lang/rust#72488
Contributor
Author
There was a problem hiding this comment.
Although this is scary!
Type ids have some edges that this stabilization exposes to more contexts. It's possible for type ids to collide (but this is a bug). Since they can change between compiler versions, it's never valid to cast a type id to its underlying value.
And looks like it was actually un-stabilized as const - so perhaps we're good to wait for it to be improved... see discussion on rust-lang/rust#75923
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.
Summary
Adds functionality for type name override via
#[sbor(type_name = "NewTypeName")].This is an addition, not a breaking change.
This would allow e.g. us to rename types without affecting their scrypto schema. For example, we could create e.g.
TimePrecisionV2and renameTimePrecisiontoTimePrecisionV1, whilst allowing them both to have an SBOR type name ofTimePrecision. The latter is required for backwards compatibility.Testing
Tests are in
sbor-tests.