MemoryFile<T>
: Wrap memory mappings over any file-like object
A safe and ergonomic mmap()
wrapper for arbitrary file-descriptor handles.
NOTE: Working release, but still in development.
Usage
MemoryFile<T>
can be used to consume any type T
that implements AsRawFd
, form a mapping over that file-descriptor, and then unmap the memory before the T
itself is dropped (which can be a reference or value.)
The MemoryFile<T>
can also be consumed back into the T
, unmapping (and optionally syncing) the memory in the process.
Examples
A function mapping file memory working on arbitrary file-descriptor holding objects.
Sized, U: ?Sized> where T: AsRawFd,
U: AsRawFd
Although, it is probably a better pattern to allow the caller to handle the mapping, and the callee to take any kind of mapping like so:
Sized, U: ?Sized> where T: AsRawFd,
U: AsRawFd
However, MappedFile<T>
also implements Borrow<[u8]>
, so any &MappedFile<T>
can be passed to any function as AsRef<[u8]>
too.
License
MIT