-
Notifications
You must be signed in to change notification settings - Fork 177
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
Switch to a better API for tagged enums for C# #1177
Conversation
Oh this is extremely nice but it is going to be a huge patch for BitCraft right? How many enums are they using? These records will also allocate, Also note we can't use Unity serialization with records according to this: https://docs.unity3d.com/Manual/CSharpCompiler.html |
No, because this affects only server-side module SDK (for now), and their modules are written in Rust.
Even then, you can't use |
As for this, I'm not sure either. Given that Unity / client C# code in general doesn't support tagged enums altogether for now, this is at least not a breaking change, but we can return to this question in the future after we integrate it into the client SDK. |
Oh perfect, no complaints from me then. |
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.
👍
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.
I'm fine with this - we don't really have support for this on the client right now anyway so nothing to break there. We'll just have to include this in the 0.10 release notes because this would break modules who were already using tagged enums
With C# records - which are available since C# 9, so covers Unity requirements as well - we can use subclassing and pattern matching to get sum types that look a lot more like Rust tagged enums. This is a breaking change but IMO worth it for the better API going forward.
fb62a16
to
c1684e4
Compare
Description of Changes
With C# records - which are available since C# 9, so covers Unity requirements as well - we can use subclassing and pattern matching to get sum types that look a lot more like Rust tagged enums than my previous approach.
For example, the following Rust code:
can now be expressed via almost equivalent C# code
This is a breaking change but IMO worth it for the better API going forward.
API and ABI breaking changes
If this is an API or ABI breaking change, please apply the
corresponding GitHub label.
Expected complexity level and risk
How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.
2
This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.
If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.
Testing
Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!