ps_datachunk/cow/implementations/
datachunk.rs

1use ps_hash::Hash;
2
3use crate::{BorrowedDataChunk, CowDataChunk, DataChunk, OwnedDataChunk};
4
5impl DataChunk for CowDataChunk<'_> {
6    fn borrow(&self) -> BorrowedDataChunk<'_> {
7        BorrowedDataChunk::from_parts(self.data_ref(), self.hash())
8    }
9
10    fn data_ref(&self) -> &[u8] {
11        match self {
12            Self::Borrowed(chunk) => chunk.data_ref(),
13            Self::Mbuf(chunk) => chunk.data_ref(),
14            Self::Owned(chunk) => chunk.data_ref(),
15        }
16    }
17
18    fn hash(&self) -> Hash {
19        match self {
20            Self::Borrowed(chunk) => chunk.hash(),
21            Self::Mbuf(chunk) => chunk.hash(),
22            Self::Owned(chunk) => chunk.hash(),
23        }
24    }
25
26    fn hash_ref(&self) -> &ps_hash::Hash {
27        match self {
28            Self::Borrowed(chunk) => chunk.hash_ref(),
29            Self::Mbuf(chunk) => chunk.hash_ref(),
30            Self::Owned(chunk) => chunk.hash_ref(),
31        }
32    }
33
34    fn into_bytes(self) -> bytes::Bytes {
35        match self {
36            Self::Borrowed(chunk) => chunk.into_bytes(),
37            Self::Mbuf(chunk) => chunk.into_bytes(),
38            Self::Owned(chunk) => chunk.into_bytes(),
39        }
40    }
41
42    fn into_owned(self) -> OwnedDataChunk {
43        match self {
44            Self::Borrowed(chunk) => chunk.into_owned(),
45            Self::Mbuf(chunk) => chunk.into_owned(),
46            Self::Owned(chunk) => chunk.into_owned(),
47        }
48    }
49}