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

tokio-io: A way to reunite ReadHalf and WriteHalf? #803

Closed
twittner opened this issue Dec 18, 2018 · 2 comments
Closed

tokio-io: A way to reunite ReadHalf and WriteHalf? #803

twittner opened this issue Dec 18, 2018 · 2 comments

Comments

@twittner
Copy link
Contributor

Version

tokio-io 0.1.10

Platform

Linux 4.19.9-arch1-1-ARCH #1 SMP PREEMPT x86_64 GNU/Linux

Description

tokio_io::AsyncRead allows to split itself into a ReadHalf and WriteHalf if Self also implements tokio_io::AsyncWrite. However I did not see a way to reunite the two halves back into the original type. The split functionality is implemented using futures::sync::Bilock which does provide a reunite method. It would be nice if tokio-io would also allow getting back the original type, e.g. via a reunite function in tokio-io/src/split.rs

/// Reunite the two halves of a previously split resource.
pub fn reunite<T>(r: ReadHalf<T>, w: WriteHalf<T>) -> Result<T, (ReadHalf<T>, WriteHalf<T>)> {
    r.handle.reunite(w.handle).map_err(|err| {
        (ReadHalf { handle: err.0 }, WriteHalf { handle: err.1 })
    })
}

I would be happy to open a PR implementing this if there is a chance of getting this merged.

@arthurprs
Copy link
Contributor

Maybe unsplit, for symmetry?

@carllerche
Copy link
Member

unsplit sounds good to me 👍

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