Provide 2 variants (partial vs. entire) for pushing/popping slices #164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow-up to #146 and #160. This makes the API surface even larger, but I think it may be worth it, any feedback is welcome!
Initially, I didn't plan to add those methods, but I wanted to add some convenience helper functions to reduce boilerplate code like this:
I implemented
copy_to_slice()andcopy_from_slice()methods on the different "chunk" types, which reduces above code to:But then I realized that this is still a bit too convoluted, and instead of creating helper methods on the "chunk" types, I might as well add helper methods to producer/consumer, which would lead to code like this:
Instead of panicking if there are too few available slots,
.unwrap()can be removed and theChunkErrorcan be handled as usual.I think this is much more straightforward, and I like it more.
However, this adds more "push/pop slice" methods, which might be confusing. But OTOH, by naming them more explicitly, it might even be less confusing with regards to whether a whole slice is copied or only part of a slice (if there are not enough slots left):
push_partial_slice()push_entire_slice()pop_partial_slice()pop_entire_slice()Any opinions on this?
Is this more confusing or more clarifying?
Regarding implementation, I decided to implement the "entire" variant and use that in the implementation of the "partial" variant. It would also work the other way round (and I tried that as well), but I think the implementation is more straightforward this way.
Benchmark results are inconclusive, there are minor regressions and some improvements in the various benchmarks. I think it is close to the measurement uncertainty.