rustolio_utils/bytes/
generic_bytes.rs1use bytes::{Buf, Bytes};
12
13pub struct GenericBytes(Box<dyn Buf + Send + Sync + 'static>);
14
15impl Default for GenericBytes {
16 fn default() -> Self {
17 Self::new(Bytes::new())
18 }
19}
20
21impl GenericBytes {
22 pub fn new(b: impl Buf + Send + Sync + 'static) -> Self {
23 Self(Box::new(b))
24 }
25}
26
27impl Buf for GenericBytes {
28 fn remaining(&self) -> usize {
29 self.0.remaining()
30 }
31
32 fn advance(&mut self, cnt: usize) {
33 self.0.advance(cnt);
34 }
35 fn chunk(&self) -> &[u8] {
36 self.0.chunk()
37 }
38}