Uh oh!
There was an error while loading. Please reload this page.
Use generic io trait implementations for Cursor when possible - #23364
Use generic io trait implementations for Cursor when possible#23364nwin wants to merge 2 commits into
Conversation
rust-highfive
commented
Mar 14, 2015
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
nwin
commented
Mar 14, 2015
It would be easy to add an implementation of |
petrochenkov
commented
Mar 14, 2015
Why |
nwin
commented
Mar 14, 2015
Good questions. I chose |
alexcrichton
commented
Mar 15, 2015
I personally do find it much nicer for these to be generic implementations rather than hard-coded, but I also fear that we don't have the right trait to operate generically with at this time. I feel that A concrete backwards-compatibility risk is that this would enable something like cc @aturon |
nwin
commented
Mar 15, 2015
The alternative to The lack of generic implementation is also an issue I have with the stdlib in general at the moment. I’m fearing that it will get messy when using a lot of third party provided types. If the author forgets to implement a trait you need, you end up having a lot of wrapper types to implement these traits yourself. In the case of reference-like types, the most natural trait to implement is |
alexcrichton
commented
Mar 15, 2015
|
petrochenkov
commented
Mar 15, 2015
|
aturon
commented
Mar 16, 2015
I tend to agree that we may want to take things a bit slow here. Note, however, that it's not exactly back-compat to add such an impl later, since it could introduce coherence conflicts with downstream crates. (It might be possible to do if we introduced a new trait at the same time.) More broadly, we've had proposals like this come up for using |
alexcrichton
commented
Mar 17, 2015
I agree! This is also somewhat covered by rust-lang/rfcs#279 |
bors
commented
Mar 24, 2015
☔ The latest upstream changes (presumably #23654) made this pull request unmergeable. Please resolve the merge conflicts. |
nwin
commented
Apr 5, 2015
Should I pursue this PR but using |
alexcrichton
commented
Apr 6, 2015
@nwin out of curiosity, do you have a use case for wanting to create a |
nwin
commented
Apr 6, 2015
My use case is a chat (IRC) server where the messages need to get distributed to many clients. For this I planned to use |
alexcrichton
commented
Apr 7, 2015
Hm currently |
alexcrichton
commented
Apr 28, 2015
Hm ok this seems to have fallen by the wayside a bit, so I'm going to close this out of inactivity for now. I don't think that the use case for this generalization is super compelling today, but it doesn't mean it won't be one day! I believe the modifications here should be fine backwards-compatible additions, so the door is still open for this. |
nwin
commented
Jul 21, 2015
I updated my implementation. Github does not seem to recognize it if that (maybe that happens if the PR gets reopened). It now uses The only drawback is, that specialized implementation for fixed-sized arrays are now ruled out as long as RFC#1210 it not accepted & implemented.
|
alexcrichton
commented
Jul 21, 2015
Yes I think that submitting a separate PR is fine to do at this point. |
This is a revival of #23364. Github didn’t recognize my updated branch there. The cursor implementation now uses `AsRef` which means that fixed-sized array can now be used with `Cursor`. Besides that, the generic implementation simplifies the code as the macro can be avoided. The only drawback is, that specialized implementation for fixed-sized arrays are now ruled out unless [RFC#1210](rust-lang/rfcs#1210) is accepted & implemented. `Box<[u8]>` cannot be used yet, but that should be mitigated by [implementing `AsRef` for `Box` and friends](https://internals.rust-lang.org/t/forward-implement-traits-on-smart-pointers-make-smart-pointers-more-transparent/2380/3). I will submit a separate PR for that later as it is an orthogonal issue.
This PR provides generic implementations of most io traits for
Cursor. The former behavior is unchanged while it is now possible to use boxed types likeBox<[u8]>or futureRc<[T]>.A generic writer implementation does not seem to be possible, because it would conflict with the desirable specialization for
Vec<u8>.