1 #![cfg_attr(not(feature = "full"), allow(dead_code))] 2 3 use crate::park::{Park, Unpark}; 4 5 use std::fmt; 6 use std::time::Duration; 7 8 pub(crate) enum Either<A, B> { 9 A(A), 10 B(B), 11 } 12 13 impl<A, B> Park for Either<A, B> 14 where 15 A: Park, 16 B: Park, 17 { 18 type Unpark = Either<A::Unpark, B::Unpark>; 19 type Error = Either<A::Error, B::Error>; 20 unpark(&self) -> Self::Unpark21 fn unpark(&self) -> Self::Unpark { 22 match self { 23 Either::A(a) => Either::A(a.unpark()), 24 Either::B(b) => Either::B(b.unpark()), 25 } 26 } 27 park(&mut self) -> Result<(), Self::Error>28 fn park(&mut self) -> Result<(), Self::Error> { 29 match self { 30 Either::A(a) => a.park().map_err(Either::A), 31 Either::B(b) => b.park().map_err(Either::B), 32 } 33 } 34 park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error>35 fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> { 36 match self { 37 Either::A(a) => a.park_timeout(duration).map_err(Either::A), 38 Either::B(b) => b.park_timeout(duration).map_err(Either::B), 39 } 40 } 41 shutdown(&mut self)42 fn shutdown(&mut self) { 43 match self { 44 Either::A(a) => a.shutdown(), 45 Either::B(b) => b.shutdown(), 46 } 47 } 48 } 49 50 impl<A, B> Unpark for Either<A, B> 51 where 52 A: Unpark, 53 B: Unpark, 54 { unpark(&self)55 fn unpark(&self) { 56 match self { 57 Either::A(a) => a.unpark(), 58 Either::B(b) => b.unpark(), 59 } 60 } 61 } 62 63 impl<A, B> fmt::Debug for Either<A, B> 64 where 65 A: fmt::Debug, 66 B: fmt::Debug, 67 { fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result68 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 69 match self { 70 Either::A(a) => a.fmt(fmt), 71 Either::B(b) => b.fmt(fmt), 72 } 73 } 74 } 75