1 extern crate either; 2 3 use {Buf, BufMut}; 4 5 use self::either::Either; 6 use self::either::Either::*; 7 use iovec::IoVec; 8 9 impl<L, R> Buf for Either<L, R> 10 where 11 L: Buf, 12 R: Buf, 13 { remaining(&self) -> usize14 fn remaining(&self) -> usize { 15 match *self { 16 Left(ref b) => b.remaining(), 17 Right(ref b) => b.remaining(), 18 } 19 } 20 bytes(&self) -> &[u8]21 fn bytes(&self) -> &[u8] { 22 match *self { 23 Left(ref b) => b.bytes(), 24 Right(ref b) => b.bytes(), 25 } 26 } 27 bytes_vec<'a>(&'a self, dst: &mut [&'a IoVec]) -> usize28 fn bytes_vec<'a>(&'a self, dst: &mut [&'a IoVec]) -> usize { 29 match *self { 30 Left(ref b) => b.bytes_vec(dst), 31 Right(ref b) => b.bytes_vec(dst), 32 } 33 } 34 advance(&mut self, cnt: usize)35 fn advance(&mut self, cnt: usize) { 36 match *self { 37 Left(ref mut b) => b.advance(cnt), 38 Right(ref mut b) => b.advance(cnt), 39 } 40 } 41 copy_to_slice(&mut self, dst: &mut [u8])42 fn copy_to_slice(&mut self, dst: &mut [u8]) { 43 match *self { 44 Left(ref mut b) => b.copy_to_slice(dst), 45 Right(ref mut b) => b.copy_to_slice(dst), 46 } 47 } 48 } 49 50 impl<L, R> BufMut for Either<L, R> 51 where 52 L: BufMut, 53 R: BufMut, 54 { remaining_mut(&self) -> usize55 fn remaining_mut(&self) -> usize { 56 match *self { 57 Left(ref b) => b.remaining_mut(), 58 Right(ref b) => b.remaining_mut(), 59 } 60 } 61 bytes_mut(&mut self) -> &mut [u8]62 unsafe fn bytes_mut(&mut self) -> &mut [u8] { 63 match *self { 64 Left(ref mut b) => b.bytes_mut(), 65 Right(ref mut b) => b.bytes_mut(), 66 } 67 } 68 bytes_vec_mut<'a>(&'a mut self, dst: &mut [&'a mut IoVec]) -> usize69 unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [&'a mut IoVec]) -> usize { 70 match *self { 71 Left(ref mut b) => b.bytes_vec_mut(dst), 72 Right(ref mut b) => b.bytes_vec_mut(dst), 73 } 74 } 75 advance_mut(&mut self, cnt: usize)76 unsafe fn advance_mut(&mut self, cnt: usize) { 77 match *self { 78 Left(ref mut b) => b.advance_mut(cnt), 79 Right(ref mut b) => b.advance_mut(cnt), 80 } 81 } 82 put_slice(&mut self, src: &[u8])83 fn put_slice(&mut self, src: &[u8]) { 84 match *self { 85 Left(ref mut b) => b.put_slice(src), 86 Right(ref mut b) => b.put_slice(src), 87 } 88 } 89 } 90