-
Notifications
You must be signed in to change notification settings - Fork 123
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
feature: Add type_name override to Describe proc macro #1671
Conversation
Benchmark for d7a020bClick to view benchmark
|
get_sbor_attribute_string_value(&attrs, "type_name")?.unwrap_or(ident.to_string()); | ||
|
||
let type_id = quote! { | ||
::sbor::RustTypeId::novel_with_code( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
TimePrecisionV2
and renameTimePrecision
toTimePrecisionV1
, whilst allowing them both to have an SBOR type name ofTimePrecision
. The latter is required for backwards compatibility.Testing
Tests are in
sbor-tests
.