-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
bevy_core: Derive useful traits on FrameCount #13291
Conversation
Didn't quite do my due diligence here, my bad. Going to quickly edit the PR body to reflect these changes, double check that the serde implementation works correctly, and edit the PR body with that info as well |
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 agree with the proposed changes, but I just have a couple small concerns around testing and the exact implementation. Thanks for contributing!
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'd like to see a comment in the code base about why you chose to use a manual serde impl (a decision I agree with!) but once that's done this LGTM :)
I can't really provide any reasoning -- I was just following the existing pattern in the crate. The traits were implemented manually for |
There's my understanding of the motivation here :) I think on the balance I probably prefer to just swap to derives, but I don't mind it. |
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
got it, thanks a bunch alice! makes sense to me |
#[test] | ||
fn test_serde_name() { | ||
let name = Name::new("MyComponent"); | ||
assert_tokens(&name, &[Token::String("MyComponent")]); |
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.
Lovely that assert_tokens
tests serialisation and deserialisation at the same time.
use serde_test::{assert_tokens, Token}; | ||
|
||
#[test] | ||
fn test_serde_name() { |
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.
Good call to test this as well!
Objective
I am emboldened by my last small PR and am here with another.
It would be nice if
FrameCount
could be used by downstream plugins that want to use frame data. The example that I have in mind isleafwing_input_playback
which has a duplicate implementation ofFrameCount
used in several structs which rely on those derives (or otherwise the higher-level structs would have to implement these traits manually). That crate, usingFrameCount
, tracks input frames and timestamps and enables various playback modes.I am aware that bevy org refrains from deriving lots of unnecessary stuff on bevy types to avoid compile time creep. It is worth mentioning the (equally reasonable) alternative that downstream crates should implement some
FrameCount
themselves if they want special behavior from it.Solution
I added derives for
PartialEq, Eq, PartialOrd, Ord
and implementations forserde::{Deserialize, Serialize}
toFrameCount
.Testing
Manually confirmed that the serde implementation works, but that's all. Let me know if I should do more here.