1use crate::object::{Object, ObjectId};
2use accessory::Accessors;
3use alloc::vec::Vec;
4
5#[derive(Debug, Clone, Accessors)]
9pub struct Blob {
10 #[access(get(cp))]
12 id: ObjectId,
13
14 #[access(get(ty(&[u8])))]
16 data: Vec<u8>,
17}
18
19impl PartialEq for Blob {
20 fn eq(&self, other: &Self) -> bool {
21 self.id == other.id
22 }
23}
24impl Eq for Blob {}
25impl PartialOrd for Blob {
26 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
27 Some(self.cmp(other))
28 }
29}
30impl Ord for Blob {
31 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
32 self.id.cmp(&other.id)
33 }
34}
35
36impl Blob {
37 pub(crate) fn new(id: ObjectId, data: Vec<u8>) -> Self {
38 Blob { id, data }
39 }
40
41 pub fn data_owned(self) -> Vec<u8> {
43 self.data
44 }
45
46 pub fn as_object(self) -> Object {
48 Object::Blob(self)
49 }
50}