shrupl/src/file/chunk.rs

37 lines
849 B
Rust
Raw Normal View History

pub struct Chunk<'t> {
data: &'t [u8],
patch_uri: &'t str,
offset: u64,
}
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={} did not fit into u64: {}", len, e))
}
pub fn get_patch_uri(&self) -> &str {
self.patch_uri
}
pub fn get_offset(&self) -> u64 {
self.offset
}
}