Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy_to_bytes consumes &mut self #473

Open
o0Ignition0o opened this issue Jan 26, 2021 · 8 comments
Open

copy_to_bytes consumes &mut self #473

o0Ignition0o opened this issue Jan 26, 2021 · 8 comments

Comments

@o0Ignition0o
Copy link

Hey everyone,

first of all I'd like to thank you for the tremendous work it took to reach 1.0 🎉

I was quite confused during a webapp's tokio upgrade path because one of my proxies would return empty (warp) response bodies after the migration.

After longer than I'd like to admit ( 😅 ) I zeroed in on the fact that copy_to_bytes() took &mut self, and had a look at the documentation:

Consumes len bytes inside self and returns new instance of Bytes with this data.

It confused me quite a bit because that's not the behavior I would expect from copy_to* methods.

There's probably a rationale behind that, and if you might have already considered move_to transfer_to and other variants, and decided otherwise, feel free to close the issue.

The fact it might confuse others as well prompted me to open this issue, and I'd gladly help rename the functions if it makes sense!

Thank's again for your time :)

@o0Ignition0o o0Ignition0o changed the title copy_to_bytes consumes &self copy_to_bytes consumes &self Jan 26, 2021
@o0Ignition0o o0Ignition0o changed the title copy_to_bytes consumes &self copy_to_bytes consumes &mut self Jan 26, 2021
@Darksonn
Copy link
Contributor

They can't just be renamed due to backwards compatibility. The most we could do is deprecate and #[doc(hidden)] it, adding an alternative.

@o0Ignition0o
Copy link
Author

o0Ignition0o commented Jan 26, 2021

Oh I see, thanks a lot for your reply!

Edit: do you think deprecation / renaming is worth pursuing ?

@carllerche
Copy link
Member

That is pretty unfortunate... we will probably need to add an alternative :'(

@carllerche
Copy link
Member

Actually, wait... it takes &mut self because it advances the internal cursor.

@carllerche
Copy link
Member

Given that &mut self is correct and it is mostly a less-than-ideal name, I don't think we should deprecate & create an alternative. We should just document the method and deal with it.

@seanmonstar
Copy link
Member

Yea, the question of the name for this method came up when it was renamed, and back then we noticed the same: the name isn't great, but there weren't any other better names.

@o0Ignition0o
Copy link
Author

I don't think we should deprecate & create an alternative. We should just document the method and deal with it.

Yeah that makes sense, it is documented already so I guess there's not much more we can do then ^^'

@nazar-pc
Copy link

read_to_bytes() would hint that there is an internal cursor that is being advanced.

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

No branches or pull requests

5 participants