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

Suggestion: Readers/Writers that work with AsyncRead/AsyncWrite #171

Closed
rjsberry opened this issue Sep 12, 2019 · 6 comments
Closed

Suggestion: Readers/Writers that work with AsyncRead/AsyncWrite #171

rjsberry opened this issue Sep 12, 2019 · 6 comments

Comments

@rjsberry
Copy link

Hi @BurntSushi.

#141 briefly touched on this, but with the coming stabilization of async/await have you had any further thoughts on how async might integrate with the csv crate?

My use case is integrating CSV logging into a larger async application. At the moment I am post-processing binary files, but it would be great to work with CSV directly.

@BurntSushi
Copy link
Owner

I have zero plans here. Ideally, csv wouldn't need to do anything for this at all. csv reading/parsing shouldn't need to care about whether something is async or not. That is, this should be achievable with some kind of adapter which provides AsyncRead/AsyncWrite implementations given std::io::Read/std::io::Write implementations.

async should not require every crate everywhere that does anything with std::io to also provide completely disjoint async code.

If someone has more data that can make a more compelling argument why I'm wrong about this, or provide a more concrete proposal, then I'll be all ears. But for now, I have no plans.

@rjsberry
Copy link
Author

Thanks for the swift response.

async should not require every crate everywhere that does anything with std::io to also provide completely disjoint async code.

Well put. And yeah, I agree - I don't see how this would be possible without providing an AsyncReader / AsyncWriter.

csv reading/parsing shouldn't need to care about whether something is async or not.

So for writing specifically the workaround here is to use Writer::from_writer with Vec and then use file abstractions in crates like tokio to perform the actual io asynchronously.

@BurntSushi
Copy link
Owner

It looks like adapters already exist: https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/struct.AllowStdIo.html

@hronro
Copy link

hronro commented Jun 11, 2020

@BurntSushi

I don't understand how AllowStdIo will work in this situation.

AllowStdIo can add AsyncRead implementation for something has implement Read, rather than adding Read implementation for something has implement AsyncRead.

Say we have a thing has implement AsyncRead, and csv::Reader::from_reader requires implementing Reader trait, so we can't use AllowStdIo to make them work together.

Suggestions: can we have something like csv::AsyncReader that can be construct from a AsyncRead or a Stream, that will be very easy to use in an async context.

@BurntSushi
Copy link
Owner

@foisonocean See: #199

@gwierzchowski
Copy link

Just wanted to mention that I have pushed csv-async to crates.io.
If there would be an intention to merge it to this crate (e.g. to reduce code duplication) I'm open for it.

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

4 participants