From 53ad102cf0e99e91445d9aea0b5ba3cc768b7566 Mon Sep 17 00:00:00 2001 From: Eddy Oyieko <67474838+mobley-trent@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:23:04 +0300 Subject: [PATCH] util: implement `Sink` for `Either` (#6239) --- tokio-util/src/either.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tokio-util/src/either.rs b/tokio-util/src/either.rs index 8a02398bc..e7fec9546 100644 --- a/tokio-util/src/either.rs +++ b/tokio-util/src/either.rs @@ -164,6 +164,39 @@ where } } +impl futures_sink::Sink for Either +where + L: futures_sink::Sink, + R: futures_sink::Sink, +{ + type Error = Error; + + fn poll_ready( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + delegate_call!(self.poll_ready(cx)) + } + + fn start_send(self: Pin<&mut Self>, item: Item) -> std::result::Result<(), Self::Error> { + delegate_call!(self.start_send(item)) + } + + fn poll_flush( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + delegate_call!(self.poll_flush(cx)) + } + + fn poll_close( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + delegate_call!(self.poll_close(cx)) + } +} + #[cfg(test)] mod tests { use super::*;