bincode-org / bincode

A binary encoder / decoder implementation in Rust.
MIT License
2.63k stars 265 forks source link

Use const functions where possible #684

Closed richardpringle closed 8 months ago

richardpringle commented 8 months ago

I just used clippy for this. I actually assume that you will not want the brunt of this change but I figured it was easier to make the change everywhere then simply pick the ones you deem acceptable (if any).

I definitey think some of the constructors should be const.

Thanks in advance!

VictorKoenders commented 8 months ago

Looks good to me.

Out of pure interest, can you check if this actually improves any of the benchmarks?

codecov[bot] commented 8 months ago

Codecov Report

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

Comparison is base (ff7a45a) 57.24% compared to head (4a77a75) 57.24%.

Files Patch % Lines
src/error.rs 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## trunk #684 +/- ## ======================================= Coverage 57.24% 57.24% ======================================= Files 51 51 Lines 4350 4350 ======================================= Hits 2490 2490 Misses 1860 1860 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

richardpringle commented 8 months ago

Looks good to me.

Out of pure interest, can you check if this actually improves any of the benchmarks?

I'm not quite sure I understand what you're asking. const shouldn't change the behaviour at all, it will only make those functions available in const context. In order to improve a benchmark, you would have to change the code at the call-site.

You should also be aware that removing const from a pub const function is a breaking change. Given the extensive use of the builder-pattern, this shouldn't be a concern, though.