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

Add AsyncBufReadExt::read_line #1556

Merged
merged 1 commit into from
May 6, 2019
Merged

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Apr 26, 2019

Also, AsyncBufReadExt::lines can be implemented using this.

@taiki-e
Copy link
Member Author

taiki-e commented Apr 27, 2019

Blocked on #1566.

EDIT: #1566 was merged.

@taiki-e taiki-e force-pushed the io-read_line branch 3 times, most recently from 3784773 to 9adc2de Compare May 3, 2019 00:59
@taiki-e
Copy link
Member Author

taiki-e commented May 3, 2019

I opened rust-lang/rust#60498 about a strange error occurring in the test.

EDIT: Fixed in rust-lang/rust#60501

@taiki-e taiki-e force-pushed the io-read_line branch 2 times, most recently from 354c38e to a4c98c0 Compare May 6, 2019 17:14
@cramertj
Copy link
Member

cramertj commented May 6, 2019

This looks good to me, but has conflicts with master-- will merge after rebase.

@taiki-e
Copy link
Member Author

taiki-e commented May 6, 2019

Rebased.

@cramertj cramertj merged commit 8d77d6f into rust-lang:master May 6, 2019
@cramertj
Copy link
Member

cramertj commented May 6, 2019

Nice!

@taiki-e taiki-e deleted the io-read_line branch May 6, 2019 23:48
let mut v = Vec::new();
assert_eq!(run(buf.read_until(b'3', &mut v)).unwrap(), 2);
assert_eq!(v, b"12");

let mut buf = MaybePending::new(b"12333");
let mut buf = b"12333".interleave_pending();
Copy link
Member

@Nemo157 Nemo157 May 7, 2019

Choose a reason for hiding this comment

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

Note that this won't add a pending in between reads that actually return data like the old implementation, it will be like Pending, Ready(b"12333"), Pending, Ready(b"").

If you want to test reading data multiple times my plan elsewhere was to use TryStreamExt::into_async_read, so something like stream::iter(vec![b"12", b"33", b"3"]).map(Ok).into_async_read().interleave_pending().

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I updated this PR after checking locally that the new test can detect problems like #1566, but the code you suggested is even better. I will open a PR

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like IntoAsyncRead should special-case consume(0) to be a noop then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Opened #1584.

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.

3 participants