ps_datachunk/cow/implementations/
datachunk.rs

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