1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
extern crate either;

use {Buf, BufMut};

use self::either::Either;
use self::either::Either::*;
use iovec::IoVec;

impl<L, R> Buf for Either<L, R>
where
    L: Buf,
    R: Buf,
{
    fn remaining(&self) -> usize {
        match *self {
            Left(ref b) => b.remaining(),
            Right(ref b) => b.remaining(),
        }
    }

    fn bytes(&self) -> &[u8] {
        match *self {
            Left(ref b) => b.bytes(),
            Right(ref b) => b.bytes(),
        }
    }

    fn bytes_vec<'a>(&'a self, dst: &mut [&'a IoVec]) -> usize {
        match *self {
            Left(ref b) => b.bytes_vec(dst),
            Right(ref b) => b.bytes_vec(dst),
        }
    }

    fn advance(&mut self, cnt: usize) {
        match *self {
            Left(ref mut b) => b.advance(cnt),
            Right(ref mut b) => b.advance(cnt),
        }
    }

    fn copy_to_slice(&mut self, dst: &mut [u8]) {
        match *self {
            Left(ref mut b) => b.copy_to_slice(dst),
            Right(ref mut b) => b.copy_to_slice(dst),
        }
    }
}

impl<L, R> BufMut for Either<L, R>
where
    L: BufMut,
    R: BufMut,
{
    fn remaining_mut(&self) -> usize {
        match *self {
            Left(ref b) => b.remaining_mut(),
            Right(ref b) => b.remaining_mut(),
        }
    }

    unsafe fn bytes_mut(&mut self) -> &mut [u8] {
        match *self {
            Left(ref mut b) => b.bytes_mut(),
            Right(ref mut b) => b.bytes_mut(),
        }
    }

    unsafe fn bytes_vec_mut<'a>(&'a mut self, dst: &mut [&'a mut IoVec]) -> usize {
        match *self {
            Left(ref mut b) => b.bytes_vec_mut(dst),
            Right(ref mut b) => b.bytes_vec_mut(dst),
        }
    }

    unsafe fn advance_mut(&mut self, cnt: usize) {
        match *self {
            Left(ref mut b) => b.advance_mut(cnt),
            Right(ref mut b) => b.advance_mut(cnt),
        }
    }

    fn put_slice(&mut self, src: &[u8]) {
        match *self {
            Left(ref mut b) => b.put_slice(src),
            Right(ref mut b) => b.put_slice(src),
        }
    }
}