Skip to content

Impl into_vec for Bytes#372

Closed
avitex wants to merge 2 commits intotokio-rs:masterfrom
avitex:into-vec
Closed

Impl into_vec for Bytes#372
avitex wants to merge 2 commits intotokio-rs:masterfrom
avitex:into-vec

Conversation

@avitex
Copy link
Copy Markdown

@avitex avitex commented Feb 21, 2020

  • Carries on from the work in PR Add conversion from Bytes to Vec #151
  • Doesn't fully close issue Bytes[Mut]::into_vec() #86 as BytesMut::into_vec is not implemented. Currently you cannot
    convert from a BytesMut to a Vec from a public interface (as like Bytes does) so I left this out for the time being.
  • I'm not 100% on the atomic guarantees here.

Side note, I've noticed there is a decent amount of repetition and other tid bits of work that can be done in this lib. Old comments referring to Inner etc, no use of cargo fmt. I'm happy to jam a decent amount of time into helping refactor, but I would first like to check no other work of this kind is being done offline so I'm not duplicating it. Would the maintainers be interested in PRs of this sort?

Additionally rename ref_count in BytesMut's Shared data to ref_cnt
to be inline with the Bytes impl.
@avitex
Copy link
Copy Markdown
Author

avitex commented Jun 18, 2020

Any updates on a possible merge of this?

@seanmonstar
Copy link
Copy Markdown
Member

I'm sorry I missed this the first time!

For this concept, my gut feeling is that adding into_vec to the vtable feels out of scope. It being there would require any new implementers (once we make the vtable public) to figure out how to convert back into a Vec. I suppose if there was simply a way to decompose the Bytes back into the ptr and vtable, then a user could (unsafely) make an into_vec themselves...

@avitex
Copy link
Copy Markdown
Author

avitex commented Jun 19, 2020

Had I known you were planning on making the vtable public, I may have have taken another approach. What if the function consumes into a box slice? Data returned in that matter will be on the heap so returning a boxed slice would make sense. Either that or returning raw parts internally (which on a clone would require first assembling to a box slice and back into raw parts to return). What would be your preference?

@seanmonstar
Copy link
Copy Markdown
Member

What do you mean by consuming into a boxed slice? What does that look like?

@avitex
Copy link
Copy Markdown
Author

avitex commented Jun 23, 2020

Changing into_vec to into_boxed_slice, or if you want to break into raw parts (which wouldn't fully make sense to me), into_raw_parts.

It's VTable specific, so I'm not sure how you're going to get around not having it required if you want the optimization.

@avitex
Copy link
Copy Markdown
Author

avitex commented Aug 18, 2020

Friendly poke on this

@avitex avitex closed this Jan 7, 2021
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.

2 participants