-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make std::io::Buffer object-safe. #18788
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon. |
cc @aturon |
Could you add a test/function to ensure that a fn _ensure_buffer_is_object_safe<T: Buffer>(x: &T) -> &Buffer {
x as &Buffer
} (The leading |
I also wonder if the two extra traits could be collapsed into a single trait (don't know a good name off the top of my head). Also, the |
I did consider making them a single trait (though I also couldn't think of a good name), in the end I broke them up - in fairness perhaps CharsBuffer is sufficient, the lines are composed of chars so the one behaviour implies the other? And although Reader and Buffer are in the prelude, it looks like BytesReader (for example) is not. Though I would agree that having lines() be available in the prelude would be nice. I'll drop the test in and merge the traits. |
@huonw I've recently proposed a convention for extension traits that would cover a combined trait. It's not the best but it gets the job done. But I do believe that in this case, having a combined extension trait is the right thing to do (given that the only role is to provide a blanket impl for I think it's fine to put the new trait(s) in the prelude as well (and Otherwise, @huonw feel free to r+ when the above and your concerns have been addressed. Thanks for the PR! |
Okay - I've merged the traits and added the new trait to the prelude, do we want to rename this trait now (to BufferExt)? |
@ricky26 Since this is going in the prelude, can you call it |
274b99a
to
ad74cc0
Compare
Okay @aturon, it's now BufferPrelude. |
@huonw is this okay to merge now? |
[breaking-change] Any uses of Buffer::lines() and Buffer::chars() will need to use the new trait std::io::BufferPrelude.
@ricky26 Sorry for the delay in getting this approved, I've sent it to bors. In general feel free to ping any of us on IRC if you're not getting a response; the rust devs have a very high email volume. |
This moves chars() and lines() out of Buffer and into separate traits (CharsBuffer and LinesBuffer respectively) - this matches the pattern used for bytes() on Reader (with BytesReader). (I came across this when I wanted a trait object of a Buffer, so that I could use read_line(); rustc errors about std::io::Buffer not being object-safe.) [breaking-change] Any uses of Buffer::lines() will need to use the new trait std::io::LinesBuffer. The same is true for Buffer::chars() with std::io::CharsBuffer.
This moves chars() and lines() out of Buffer and into separate traits (CharsBuffer and LinesBuffer respectively) - this matches the pattern used for bytes() on Reader (with BytesReader).
(I came across this when I wanted a trait object of a Buffer, so that I could use read_line(); rustc errors about std::io::Buffer not being object-safe.)
[breaking-change]
Any uses of Buffer::lines() will need to use the new trait std::io::LinesBuffer.
The same is true for Buffer::chars() with std::io::CharsBuffer.