bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Bytes::drain

Open stepancheg opened this issue 7 years ago • 9 comments

stepancheg avatar May 28 '17 22:05 stepancheg

Could we provide this w/ a drain API to mirror std?

carllerche avatar May 30 '17 17:05 carllerche

What should be a result of drain?

stepancheg avatar May 30 '17 17:05 stepancheg

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

carllerche avatar May 30 '17 17:05 carllerche

Vec::drain returns an iterator. Do you think Bytes::drain should return an iterator too?

stepancheg avatar May 30 '17 17:05 stepancheg

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.

carllerche avatar May 30 '17 17:05 carllerche

I mean I doubt result of drain on Bytes will ever be used as iterator, but OK.

stepancheg avatar May 30 '17 17:05 stepancheg

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.

stepancheg avatar Jun 02 '17 23:06 stepancheg

Compilation is failed because Bound is not available in 0.1.10. Should I reimplement RangeParameter without Bound?

stepancheg avatar Jun 02 '17 23:06 stepancheg

Updated the PR with Bound copied to bytes.

stepancheg avatar Jun 18 '17 19:06 stepancheg