From 17851c1f05598a0ec223bca292befbf1d225ac42 Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Sun, 12 Nov 2023 19:23:53 -0600 Subject: [PATCH] provide a mechanism to determine if io read/write halves are from the same stream --- futures-util/src/io/split.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index 3f1b9af456..81d1e6dcb5 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -31,6 +31,13 @@ pub(super) fn split(t: T) -> (ReadHalf, WriteHalf< (ReadHalf { handle: a }, WriteHalf { handle: b }) } +impl ReadHalf { + /// Checks if this `ReadHalf` and some `WriteHalf` were split from the same stream. + pub fn is_pair_of(&self, other: &WriteHalf) -> bool { + self.handle.is_pair_of(&other.handle) + } +} + impl ReadHalf { /// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back /// together. Succeeds only if the `ReadHalf` and `WriteHalf` are @@ -42,6 +49,13 @@ impl ReadHalf { } } +impl WriteHalf { + /// Checks if this `WriteHalf` and some `ReadHalf` were split from the same stream. + pub fn is_pair_of(&self, other: &ReadHalf) -> bool { + self.handle.is_pair_of(&other.handle) + } +} + impl WriteHalf { /// Attempts to put the two "halves" of a split `AsyncRead + AsyncWrite` back /// together. Succeeds only if the `ReadHalf` and `WriteHalf` are