serial
Avril 3 years ago
parent 300fcfd4d8
commit 13980b8cd2
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -3,6 +3,7 @@
mod state;
mod pool;
mod map;
mod job;
fn main() {

@ -0,0 +1,61 @@
use std::ops::RangeBounds;
use std::slice::SliceIndex;
use std::{fs,io};
use std::path::Path;
use memmap::MmapMut;
#[derive(Debug)]
pub struct MemoryMapMut
{
file: fs::File,
map: MmapMut,
}
impl AsRef<[u8]> for MemoryMapMut
{
fn as_ref(&self) -> &[u8]
{
&self.map[..]
}
}
impl AsMut<[u8]> for MemoryMapMut
{
fn as_mut(&mut self) -> &mut [u8]
{
&mut self.map[..]
}
}
impl MemoryMapMut
{
#[inline] pub fn as_slice_mut(&mut self) -> &mut [u8]
{
self.as_mut()
}
#[inline] pub fn as_slice(&self) -> &[u8]
{
self.as_ref()
}
pub fn open(from: impl AsRef<Path>) -> io::Result<Self>
{
let file = fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(from)?;
Ok(Self{
map: unsafe{ MmapMut::map_mut(&file)? },
file,
})
}
}
#[inline] pub unsafe fn slice_mut<'a, 'b, T, R: RangeBounds<usize> + SliceIndex<[T], Output=[T]>>(what: &'a mut [T], range: R)-> &'b mut [T]
where 'a: 'b
{
&mut what[range]
}
Loading…
Cancel
Save