Skip to content

Commit 17851c1

Browse files
tones111taiki-e
authored andcommitted
provide a mechanism to determine if io read/write halves are from the same stream
1 parent 4910799 commit 17851c1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

futures-util/src/io/split.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ pub(super) fn split<T: AsyncRead + AsyncWrite>(t: T) -> (ReadHalf<T>, WriteHalf<
3131
(ReadHalf { handle: a }, WriteHalf { handle: b })
3232
}
3333

34+
impl<T> ReadHalf<T> {
35+
/// Checks if this `ReadHalf` and some `WriteHalf` were split from the same stream.
36+
pub fn is_pair_of(&self, other: &WriteHalf<T>) -> bool {
37+
self.handle.is_pair_of(&other.handle)
38+
}
39+
}
40+
3441
impl<T: Unpin> ReadHalf<T> {
3542
/// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back
3643
/// together. Succeeds only if the `ReadHalf<T>` and `WriteHalf<T>` are
@@ -42,6 +49,13 @@ impl<T: Unpin> ReadHalf<T> {
4249
}
4350
}
4451

52+
impl<T> WriteHalf<T> {
53+
/// Checks if this `WriteHalf` and some `ReadHalf` were split from the same stream.
54+
pub fn is_pair_of(&self, other: &ReadHalf<T>) -> bool {
55+
self.handle.is_pair_of(&other.handle)
56+
}
57+
}
58+
4559
impl<T: Unpin> WriteHalf<T> {
4660
/// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back
4761
/// together. Succeeds only if the `ReadHalf<T>` and `WriteHalf<T>` are

0 commit comments

Comments
 (0)