use bytes::{Buf, Bytes};
use crate::CowBytes;
impl Buf for CowBytes<'_> {
#[inline]
fn remaining(&self) -> usize {
self.len()
}
#[inline]
fn chunk(&self) -> &[u8] {
self.as_slice()
}
#[inline]
fn advance(&mut self, cnt: usize) {
match self {
Self::Borrowed(bytes) => *bytes = &bytes[cnt..],
Self::Shared(bytes) => bytes.advance(cnt),
}
}
#[inline]
fn copy_to_bytes(&mut self, len: usize) -> Bytes {
match self {
Self::Borrowed(bytes) => {
let (head, tail) = bytes.split_at(len);
*bytes = tail;
Bytes::copy_from_slice(head)
}
Self::Shared(bytes) => bytes.copy_to_bytes(len),
}
}
}