embedded_io/impls/
slice_ref.rs1use crate::{BufRead, ErrorType, Read};
2
3impl ErrorType for &[u8] {
4    type Error = core::convert::Infallible;
5}
6
7impl Read for &[u8] {
12    #[inline]
13    fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
14        let amt = core::cmp::min(buf.len(), self.len());
15        let (a, b) = self.split_at(amt);
16
17        if amt == 1 {
21            buf[0] = a[0];
22        } else {
23            buf[..amt].copy_from_slice(a);
24        }
25
26        *self = b;
27        Ok(amt)
28    }
29}
30
31impl BufRead for &[u8] {
32    #[inline]
33    fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
34        Ok(*self)
35    }
36
37    #[inline]
38    fn consume(&mut self, amt: usize) {
39        *self = &self[amt..];
40    }
41}