simpler, less lifetime-y, solution

This commit is contained in:
husky 2023-08-13 18:42:36 -07:00
parent 3b9bdece58
commit 5f70d44eea
No known key found for this signature in database
GPG key ID: 6B3D8CB511646891

View file

@ -3,11 +3,14 @@
extern crate alloc;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
// i chose this arbitrarily, but i don't think that many people will need to access over 67 million terabytes of data from a disk
pub type Index = u64;
pub type Timestamp = u64;
/// # BlockDevice
/// interface for accessing a block device, i.e. a device that can be randomly accessed in fixed-size blocks
/// will be implemented in vapblock_* libraries
@ -28,24 +31,26 @@ pub trait BlockDevice {
/// # BasicROPartition
/// interface for a partition from a `BasicROPartitionTable`
/// must implement `BlockDevice`
pub trait BasicROPartition: BlockDevice {
pub trait BasicROPartition {
/// returns a `&str` of this partition's type
/// implementation-specific
fn partition_type<'a>(&self) -> &'a str;
fn partition_type(&self) -> String;
/// returns this partition's size in bytes
fn size(&self) -> Index;
/// returns offset in bytes for accessing this partition from the beginning of the block device
fn offset(&self) -> Index;
}
/// # BasicROPartitionTable
/// interface for basic interactions with a partition table over a block device
pub trait BasicROPartitionTable<T: BasicROPartition, Sized> {
pub trait BasicROPartitionTable<T: BasicROPartition, D: BlockDevice> {
/// must be called before any other methods
fn init(&mut self, block_device: &mut dyn BlockDevice);
/// returns false if no valid partition table is found
fn init(&mut self, block_device: &mut D) -> bool;
/// returns number of partitions
fn partition_count(&self) -> usize;
/// returns Vec of (partiton_name: &str, partition: BasicROPartition)
fn partitions<'a>(&self) -> Vec<(&'a str, &'a mut T)>;
/// returns Vec of (partiton_name: String, partition: T)
fn partitions(&mut self) -> Vec<(String, T)>;
}
/// # BasicROFile