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

io: add AsyncSeek trait #1924

Merged
merged 1 commit into from
Dec 11, 2019
Merged

Conversation

notriddle
Copy link
Contributor

Motivation

We want to have a trait for seeking, since there's more than one object you might want to seek. This PR implements it for File and Cursor, and there are clients with their own seekable objects.

This is a tweaked version of #1641, with the code changed to use two functions instead of one, as requested in #1641 (comment).

Solution

The purpose behind using two functions is, essentially, to make the interface less fragile. If start_seek returns Pending, then that means nothing has happened yet. Otherwise, it has. This rule, that Pending means no side effects, is a common convention throughout Tokio's low-level API.

The function that retrieves the result, poll_complete, is the same way.

cc #1256

Closes #776

Related: rust-lang/futures-rs#1553

@notriddle notriddle force-pushed the async-seek-ext branch 2 times, most recently from b82bcc4 to f89a29f Compare December 10, 2019 19:27
@notriddle
Copy link
Contributor Author

OK. Fixed the formatting problems.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
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 👍 thanks!

@carllerche carllerche merged commit 24cd6d6 into tokio-rs:master Dec 11, 2019
@notriddle notriddle deleted the async-seek-ext branch December 11, 2019 21:05
@taiki-e taiki-e mentioned this pull request Dec 16, 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.

tokio-io, tokio-fs: No impl for Seek / No trait AsyncSeek
3 participants