Uh oh!
There was an error while loading. Please reload this page.
add back bufferless read_to_string/read_to_end methods - #970
Conversation
629b0b4 to
a17468dCompareThere was a problem hiding this comment.
Is there a missing example before this?
There was a problem hiding this comment.
Actually it's just a superfluous Or this: ;) I updated the PR
There was a problem hiding this comment.
Don't these conflict with the existing read_to_end and read_to_string methods?
There was a problem hiding this comment.
Good point. What's the state of method overloading in Rust? I've been basically away from Rust for the last couple of months which means I have to start over. If there's no such thing as method overloading I'd need to give them other names.
There was a problem hiding this comment.
You can provide multiple methods of the same name from differing traits, and use UFCS (ie ReadExt::read_to_end(&mut rdr, Vec::new())) to differentiate. But that would not improve the convenience you mentioned in this RFC. You'd need a new name.
There was a problem hiding this comment.
read_into_vec and read_into_string, possibly
netvl
commented
Mar 13, 2015
👍. There should be a simple way to do simple things. |
cburgdorf
commented
Mar 13, 2015
Also created a PR against the source rust-lang/rust#23335 |
alexcrichton
commented
Mar 13, 2015
There were two concerns which motivated moving to taking a buffer instead of returning it, the first of which you've discussed here (performance), but perhaps the more important one is the loss of information. The APIs for |
cburgdorf
commented
Mar 15, 2015
Sorry @alexcrichton I may not see the forrest for the trees. How is this |
seanmonstar
commented
Mar 16, 2015
With read_to_string, even if there's an error, all previously read data has On Sun, Mar 15, 2015, 3:13 PM Christoph Burgdorf notifications@github.com
|
cburgdorf
commented
Mar 16, 2015
Ah, sure. I see it. How about a special error type that will include the |
alexcrichton
commented
Mar 16, 2015
It is plausible to create a |
cburgdorf
commented
Mar 16, 2015
I understand the stance you take on that. We probably look at this from too different perspectives. For me, it just feels strange not to have such methods on the The way I see it, we should follow the principle of least astonishment here. |
rkjnsn
commented
Mar 19, 2015
I like this. Getting the contents as a newly-created
I don't think this should be a concern. Even with the current I definitely don't think it's worth adding a I think combined with |
reem
commented
Mar 19, 2015
I think we should wait to see how much of a problem this is once we have a larger body of rust code and add this later. This is a very easy API to add later but quite an awkward one to keep around if we decide we don't want any data-losing APIs . |
Diggsey
commented
Mar 24, 2015
Instead of specifically a ReadIntoStringError, there could be a PartialReadError or similar, which can be used by any read operation which might fail partway through. The error would allow access to the partially read data. |
cburgdorf
commented
Apr 2, 2015
Ok, for now I created a I didn't manage to get the tests working yet, so I'm not actually sure if it works. |
cburgdorf
commented
Apr 2, 2015
Never mind, it's working now with version 0.1.0 |
archer884
commented
Apr 2, 2015
Commenting just because I'm an example of one of those .NET guys who was surprised (astonished! :P) to find there was no trivial way to do this. I guessed why it wasn't there (the reasons mentioned above) and figured the justification was that it's so easy to add that, if I want it, I'm expected to do it myself... But I'd be totally cool with this being a thing I didn't have to implement, too. :) |
cburgdorf
commented
Apr 2, 2015
Haha, awesome. You are validating my theory ;)
For now just use my readext crate |
jnicklas
commented
Apr 2, 2015
Imagine the case of reading a configuration file. This will be done once at the start of the program, so is hardly performance critical, and there isn't much use in loading half a configuration file, so it's really all or nothing. That kind of thing is a lot less convenient with the revised IO APIs than it was before. |
aturon
commented
Apr 9, 2015
Thanks for the RFC! The goal of the recent IO reform was to provide high-performance, low-level APIs that map as directly to system APIs as possible, and can be used to build various higher-level abstractions and conveniences. While additional conveniences as proposed here may eventually be prudent to add to |
The
Readtrait lost it'sread_to_stringandread_to_endmethods that didn't require to pass a buffer. That comes as a small convenience loss. @steveklabniksuggested to write a PR to bring them back.Rendered view