use std::fs::read_to_string; pub unsafe trait VirtualMemoryApi: Sized + Drop { type Reservation<'s>: Reservation + 's where Self: 's; fn getPageSize(&self) -> usize; fn reserveMemory<'s>(&'s self, pagesCount: usize) -> Option>; unsafe fn extendReservation<'s>( &'s self, base: &Self::Reservation<'s>, pagesCount: usize, ) -> ExtendResult>; } pub unsafe trait Reservation: Sized + Ord + Drop { fn getPageSize(&self) -> usize; fn pagesCount(&self) -> usize; unsafe fn commitPages(&mut self, indexOfFirst: usize, count: usize) -> *mut [u8]; unsafe fn decommitPages(&mut self, indexOfFirst: usize, count: usize); unsafe fn release(self); fn isFollowedBy(&self, next: &Self) -> bool; fn isPrecededBy(&self, next: &Self) -> bool { return next.isFollowedBy(self); } } pub enum ExtendResult { OutOfMemory, ContinuationIsBusy, Success(T), } impl ExtendResult { pub fn map(&self, caster: impl FnOnce(&T) -> R) -> ExtendResult { match self { ExtendResult::Success(v) => { return ExtendResult::Success(caster(&v)); } ExtendResult::ContinuationIsBusy => return ExtendResult::ContinuationIsBusy, ExtendResult::OutOfMemory => return ExtendResult::OutOfMemory, } } pub fn map_into(self, caster: impl FnOnce(T) -> R) -> ExtendResult { match self { ExtendResult::Success(v) => { return ExtendResult::Success(caster(v)); } ExtendResult::ContinuationIsBusy => return ExtendResult::ContinuationIsBusy, ExtendResult::OutOfMemory => return ExtendResult::OutOfMemory, } } }