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
use bytes::Buf;
use iovec::IoVec;

/// A `Buf` wrapping a static byte slice.
#[derive(Debug)]
pub(crate) struct StaticBuf(pub(crate) &'static [u8]);

impl Buf for StaticBuf {
    #[inline]
    fn remaining(&self) -> usize {
        self.0.len()
    }

    #[inline]
    fn bytes(&self) -> &[u8] {
        self.0
    }

    #[inline]
    fn advance(&mut self, cnt: usize) {
        self.0 = &self.0[cnt..];
    }

    #[inline]
    fn bytes_vec<'t>(&'t self, dst: &mut [&'t IoVec]) -> usize {
        if dst.is_empty() || self.0.is_empty() {
            0
        } else {
            dst[0] = self.0.into();
            1
        }
    }
}