use std::fmt; pub struct Chunk<'t> { data: &'t [u8], patch_uri: &'t str, offset: u64, } impl fmt::Debug for Chunk<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Chunk") .field("patch_uri", &self.patch_uri) .field("offset", &self.offset) .field("data.len()", &self.data.len()) .finish_non_exhaustive() } } impl<'t> Chunk<'t> { pub fn new(data: &'t [u8], patch_uri: &'t str, offset: u64) -> Self { Self { data, patch_uri, offset, } } pub fn get_data(&self) -> &[u8] { self.data } pub fn get_length(&self) -> u64 { let len = self.data.len(); // BOOKMARK this might **panic** on platforms where `usize` has more than 64 bit. // Also, you've allocated more than 2 EiB ... in ONE chunk. // Whoa! Maybe just chill? u64::try_from(len).unwrap_or_else(|e| panic!("usize={len} did not fit into u64: {e}")) } pub fn get_patch_uri(&self) -> &str { self.patch_uri } pub fn get_offset(&self) -> u64 { self.offset } }