farena 0.1.0

A file-backed arena allocator using pread for RSS-conscious byte storage
Documentation
/// Metadata for locating a stored entry within a [`crate::FileArena`].
///
/// Uses `u16` for file index (max 65535 files) and `u32` for offset/length
/// (max 4GB per file).
#[derive(Clone, Debug, Default, Copy)]
pub struct Location {
    pub file_index: u16,
    pub offset: u32,
    pub len: u32,
}

impl Location {
    /// Creates a new `Location`, panicking if offset or len exceed `u32::MAX`.
    pub fn new(file_index: u16, offset: usize, len: usize) -> Self {
        Self {
            file_index,
            offset: u32::try_from(offset)
                .expect("Location: offset exceeds u32::MAX (4GB file limit)"),
            len: u32::try_from(len).expect("Location: len exceeds u32::MAX (4GB file limit)"),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    #[should_panic(expected = "offset exceeds u32::MAX")]
    fn new_panics_on_large_offset() {
        Location::new(0, u32::MAX as usize + 1, 10);
    }

    #[test]
    #[should_panic(expected = "len exceeds u32::MAX")]
    fn new_panics_on_large_len() {
        Location::new(0, 10, u32::MAX as usize + 1);
    }
}