ps_datachunk/cow/implementations/
datachunk.rs1use crate::{BorrowedDataChunk, CowDataChunk, DataChunk, OwnedDataChunk};
2
3impl DataChunk for CowDataChunk<'_> {
4 fn borrow(&self) -> BorrowedDataChunk<'_> {
5 BorrowedDataChunk::from_parts_unchecked(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_ref(&self) -> &ps_hash::Hash {
17 match self {
18 Self::Borrowed(chunk) => chunk.hash_ref(),
19 Self::Mbuf(chunk) => chunk.hash_ref(),
20 Self::Owned(chunk) => chunk.hash_ref(),
21 }
22 }
23
24 fn into_bytes(self) -> bytes::Bytes {
25 match self {
26 Self::Borrowed(chunk) => chunk.into_bytes(),
27 Self::Mbuf(chunk) => chunk.into_bytes(),
28 Self::Owned(chunk) => chunk.into_bytes(),
29 }
30 }
31
32 fn into_owned(self) -> OwnedDataChunk {
33 match self {
34 Self::Borrowed(chunk) => chunk.into_owned(),
35 Self::Mbuf(chunk) => chunk.into_owned(),
36 Self::Owned(chunk) => chunk.into_owned(),
37 }
38 }
39}