Module rsfs::mem::unix [] [src]

This module provides an in-memory filesystem that follows Unix semantics.

This module, when used directly, is cross-platform. This module imitates a Unix filesystem as closely as possible, meaning if you create a directory without executable permissions, you cannot do anything inside of it.

Example

use std::io::{Read, Seek, SeekFrom, Write};
use std::path::PathBuf;

use rsfs::*;
use rsfs::unix_ext::*;
use rsfs::mem::unix::FS;

let fs = FS::new();
assert!(fs.create_dir_all("a/b/c").is_ok());

// writing past the end of a file zero-extends to the write position
let mut wf = fs.create_file("a/f").unwrap();
assert_eq!(wf.write_at(b"hello", 100).unwrap(), 5);

let mut rf = fs.open_file("a/f").unwrap();
let mut output = [1u8; 5];
assert_eq!(rf.read(&mut output).unwrap(), 5);
assert_eq!(&output, &[0, 0, 0, 0, 0]);

assert_eq!(rf.seek(SeekFrom::Start(100)).unwrap(), 100);
assert_eq!(rf.read(&mut output).unwrap(), 5);
assert_eq!(&output, b"hello");

Structs

DirBuilder

A builder used to create directories in various manners.

DirEntry

Entries returned by the ReadDir iterator.

FS

An in-memory struct that satisfies rsfs::GenFS.

File

A view into a file on the filesystem.

FileType

Returned from Metadata::file_type, this structure represents the type of a file.

Metadata

Metadata information about a file.

OpenOptions

Options and flags which can be used to configure how a file is opened.

Permissions

Representation of the various permissions on a file.

ReadDir

Iterator over entries in a directory.