Skip to content
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

Add getters for current configuration values #681

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

shahn
Copy link
Contributor

@shahn shahn commented Nov 12, 2023

This was inspired by suggestions provided in #598, thanks a lot to @VictorKoenders.

Fixes #598.

This was inspired by suggestions provided in bincode-org#598, thanks a lot to
@VictorKoenders.

Fixes bincode-org#598.
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 29 lines in your changes are missing coverage. Please review.

Comparison is base (dd82a9c) 57.32% compared to head (9763ccd) 57.24%.

Files Patch % Lines
src/varint/decode_unsigned.rs 68.91% 23 Missing ⚠️
src/config.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk     #681      +/-   ##
==========================================
- Coverage   57.32%   57.24%   -0.08%     
==========================================
  Files          51       51              
  Lines        4344     4350       +6     
==========================================
  Hits         2490     2490              
- Misses       1854     1860       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@VictorKoenders
Copy link
Contributor

Sorry for the late response, I was going to think about this over the weekend and then Factorio happened and now it's a month later.

A couple of things we've been thinking about:

  • Not sure what derive attributes we want on the enums, PartialEq, Eq is maybe not needed, Clone or Debug might be? We're not sure
  • It would be nice if we could have const fn in traits. We were thinking of adding #[inline(always)] to the implementation functions but I don't want to do that before we actually benchmark that it is faster/slower, and I think that's outside of the scope of this PR.

Other than that it looks good, thanks for the contribution!

@VictorKoenders VictorKoenders merged commit ff7a45a into bincode-org:trunk Dec 11, 2023
74 checks passed
@shahn
Copy link
Contributor Author

shahn commented Dec 11, 2023

Thanks for the merge, I think PartialEq and Eq are needed to ensure you can actually do something with the config values. Debug could be nice, but is not required to do something useful. Or perhaps I misunderstood your question?

@VictorKoenders
Copy link
Contributor

You understood my question correctly.

I think PartialEq and Eq are needed to ensure you can actually do something with the config values

You can still match on the variants. This is what we do in bincode currently, the following code will still work without PartialEq, Eq:

                Ok(match D::C::ENDIAN {
                    Endianness::Little => u16::from_le_bytes(bytes),
                    Endianness::Big => u16::from_be_bytes(bytes),
                })

But this will not:

if D::C::ENDIAN ==  Endianness::Little {
    panic!("Only big endian supported");
}

But I'm also not sure if there's a downside to adding this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exposing config to implement custom Encode/Decode
2 participants