bytes
bytes copied to clipboard
Bytes::drain
Could we provide this w/ a drain
API to mirror std?
What should be a result of drain
?
Basically copy this but have our own RangeArgument
trait until that becomes stable: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
Vec::drain
returns an iterator. Do you think Bytes::drain
should return an iterator too?
Yeah, we should copy it. If the iterator is dropped the compiler should be able to optimize the work fairly easily. Benchmarks should reflect this.
I mean I doubt result of drain
on Bytes
will ever be used as iterator, but OK.
I've updated the PR with huge patch.
I believe it is mostly OK, however, there's an issue: Drain
is the same for Bytes
and BytesMut
. And it contains a field to distinguish between Bytes
and BytesMut
to enable optimization for BytesMut
later.
Probably Bytes
should have two different Drain
types, but I couldn't think of good names for the types.
Compilation is failed because Bound
is not available in 0.1.10. Should I reimplement RangeParameter
without Bound
?
Updated the PR with Bound
copied to bytes
.