-
Notifications
You must be signed in to change notification settings - Fork 41
Consider adding io::read_repeating
#82
Comments
I'm having trouble just grokking the 6 (!) type parameters here... Perhaps this could be implemented externally first, see if it gains traction, and then maybe move in? |
Yeah, it's definitely hard to read. I'm not sure how to make that easier. The basic idea is just that you're reading again and again into a user-provided buffer and passing a reference to the data read into a closure which can handle the data appropriately, either performing some side-effect or producing a Future of some data. |
I'd be happy to spin it into a gist/PR/its own crate if you think that would make the intent clearer. I don't think many people would download a crate just for this function, both because of overhead and because of the difficulty of discovering the functionality. The goal is just to provide an alternative of sorts to |
I agree that discoverability is a problem yeah but it's not really tenable for us to just add every combinator we can think of to tokio-io? I feel like we'd just need some threshold for inclusion beyond "a PR was sent" although I'm not quite sure what precisely such a threshold would be... |
Yeah, I totally get that. I see |
I've written a prototype implementation of this here (FWIW there are only 4 type parameters 😄). |
Ah so this is sort of where the |
Yes, tokio-io shouldn't include all possible permutations. It is totally fine to move helpers to external crates. |
Closing this was leaning towards "won't merge" and there has been no followup discussion. Please open a new issue if you want to continue this discussion. |
The current
BytesCodec
implementation is convenient, but as discussed it requires allocating aBytesMut
for the data. There should be an easy way to get a stream of bytes out of anAsyncRead
without allocating.One option is to use
io::read
andstream::unfold
:This is pretty unergonomic, though. Consider adding a function like this:
where
RepeatingRead<R, B, F, Fut, It>
implementsStream<Item = It, Error = E>
.Using it would look like this:
This could potentially help with tokio-rs/tokio-core#276.
However, it also feels like this overlaps quite a bit with the existing encoder/decoder functionality. It seems like the main difference is passing in a reference to a user-provided buffer instead of yielding a
BytesMut
. Comparatively,read_repeating
is limiting to the end-user because they must either be able to yield an item from any incoming chunk of data, or they must save intermediate state in their closure upvars. In return,read_repeating
reduces the number of allocations.The text was updated successfully, but these errors were encountered: