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

Read write helpers #896

Merged
merged 4 commits into from
Feb 20, 2019
Merged

Read write helpers #896

merged 4 commits into from
Feb 20, 2019

Conversation

faern
Copy link
Contributor

@faern faern commented Feb 15, 2019

Motivation

tokio-fs exposes a similar interface as std::fs. Some time ago very convenient helpers for reading and writing entire files with a single function call were added to the standard library. The stabilization discussion is available here: rust-lang/rust#46588

tokio-fs don't have these convenient helpers. So just opening a file and reading/writing to it is slightly more cumbersome than it would need to be. I figured that if the community reached consensus on adding these to the standard library, the same arguments would hold for tokio-fs as well.

Solution

Adding two custom futures, that join File::open + read_to_end and File::create + write_all.

The read future also polls the fs for metadata and pre-allocates the buffer accordingly. Just like what std::fs::read does.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks great to me ❤️

@carllerche carllerche merged commit 1cf5f73 into tokio-rs:master Feb 20, 2019
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

Successfully merging this pull request may close these issues.

2 participants