Skip to content

Commit

Permalink
provide a mechanism to determine if io read/write halves are from the…
Browse files Browse the repository at this point in the history
… same stream
  • Loading branch information
tones111 authored and taiki-e committed Dec 24, 2023
1 parent 4910799 commit 17851c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions futures-util/src/io/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub(super) fn split<T: AsyncRead + AsyncWrite>(t: T) -> (ReadHalf<T>, WriteHalf<
(ReadHalf { handle: a }, WriteHalf { handle: b })
}

impl<T> ReadHalf<T> {
/// Checks if this `ReadHalf` and some `WriteHalf` were split from the same stream.
pub fn is_pair_of(&self, other: &WriteHalf<T>) -> bool {
self.handle.is_pair_of(&other.handle)
}
}

impl<T: Unpin> ReadHalf<T> {
/// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back
/// together. Succeeds only if the `ReadHalf<T>` and `WriteHalf<T>` are
Expand All @@ -42,6 +49,13 @@ impl<T: Unpin> ReadHalf<T> {
}
}

impl<T> WriteHalf<T> {
/// Checks if this `WriteHalf` and some `ReadHalf` were split from the same stream.
pub fn is_pair_of(&self, other: &ReadHalf<T>) -> bool {
self.handle.is_pair_of(&other.handle)
}
}

impl<T: Unpin> WriteHalf<T> {
/// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back
/// together. Succeeds only if the `ReadHalf<T>` and `WriteHalf<T>` are
Expand Down

0 comments on commit 17851c1

Please sign in to comment.