Module std::memfs
An in-memory file system for tests: MemFs serves std::fs::Fs over the root's
Loopback, whose file ops reach the simulated tree on every backend, interpreted and native,
whatever the run's world. A #[test] installs it and runs a tool's with Fs code against
files it made, the same way every time. The tree is empty when the run starts.
MemTree adds one op to Fs, root(), the tree's root directory. Only the code that
installs MemFs holds MemTree; the code it calls with Fs reaches only the descriptors it
is handed, as under std::fs's executors.
Source: std/memfs.weir; committed interface: std/memfs.iface. Index
- effect
MemTree:std::fs::Fsplus a way in: the root directory of the in-memory tree. - handler
MemFs: The in-memory file system:with MemFs(slots()) { let d = root(); … }(needs the root'sLoopback;slots()is its table). The body is its one strand, one op in flight at a time.
effect MemTree
pub effect MemTree : Fs default portable migrates cross {
once fn root() -> Result<Fd, Int>;
}
std::fs::Fs plus a way in: the root directory of the in-memory tree.
op root
once fn root() -> Result<Fd, Int>;
Control kind once: the clause takes the continuation (cont k) and resumes or cancels it, so the perform is a suspension and an abort edge.
The simulated tree's root, opened as a directory.
handler MemFs
pub handler MemFs(s: Slots<Unit, once>): shared cross for MemTree with Loopback
The in-memory file system: with MemFs(slots()) { let d = root(); … } (needs the root's
Loopback; slots() is its table). The body is its one strand, one op in flight at a time.
Handles MemTree, with clauses:
once fn root() cont konce fn open(dir: &Fd, path: &[u8], flags: Int) cont konce fn read_at(f: &Fd, b: &mut [u8], off: usize) cont konce fn write_at(f: &Fd, b: &[u8], off: usize) cont konce fn sync(f: &Fd) cont konce fn size(f: &Fd) cont konce fn mkdir(dir: &Fd, path: &[u8]) cont konce fn remove(dir: &Fd, path: &[u8]) cont konce fn rename(dir: &Fd, from: &[u8], to: &[u8]) cont konce fn list(dir: &Fd, b: &mut [u8], at: usize) cont klinear fn close(fd: Fd) cont k