holochain_integrity_types/entry/
app_entry_bytes.rs

1use super::EntryError;
2use super::ENTRY_SIZE_LIMIT;
3use holochain_serialized_bytes::prelude::*;
4
5/// Newtype for the bytes comprising an App entry
6#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
7pub struct AppEntryBytes(pub SerializedBytes);
8
9impl std::fmt::Debug for AppEntryBytes {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        f.write_fmt(format_args!(
12            "AppEntryBytes({})",
13            holochain_util::hex::many_bytes_string(self.0.bytes())
14        ))
15    }
16}
17
18impl AppEntryBytes {
19    /// Get the inner SerializedBytes
20    pub fn into_sb(self) -> SerializedBytes {
21        self.0
22    }
23}
24
25impl AsRef<SerializedBytes> for AppEntryBytes {
26    fn as_ref(&self) -> &SerializedBytes {
27        &self.0
28    }
29}
30
31impl std::borrow::Borrow<SerializedBytes> for AppEntryBytes {
32    fn borrow(&self) -> &SerializedBytes {
33        &self.0
34    }
35}
36
37impl std::ops::Deref for AppEntryBytes {
38    type Target = SerializedBytes;
39
40    fn deref(&self) -> &Self::Target {
41        &self.0
42    }
43}
44
45impl TryFrom<SerializedBytes> for AppEntryBytes {
46    type Error = EntryError;
47
48    fn try_from(sb: SerializedBytes) -> Result<Self, EntryError> {
49        let size = sb.bytes().len();
50        if size > ENTRY_SIZE_LIMIT {
51            Err(EntryError::EntryTooLarge(size))
52        } else {
53            Ok(Self(sb))
54        }
55    }
56}
57
58impl From<AppEntryBytes> for SerializedBytes {
59    fn from(aeb: AppEntryBytes) -> Self {
60        UnsafeBytes::from(aeb.0).into()
61    }
62}