rsfs_tokio/lib.rs
1//! A generic filesystem with disk and in-memory implementations.
2//!
3//! # Reason for existence
4//!
5//! The [`std::fs`] module provides functions to manipulate the filesytem, and these functions are
6//! good. However, if you have code that uses `std::fs`, it is difficult to ensure that your code
7//! handles errors properly because generally, you are not testing on an already broken machine.
8//! You could attempt to set up FUSE, which, although doable, is involved.
9//!
10//! This crate provides a generic filesystem with various implementations. At the moment, only
11//! normal (non-injectable) disk and in-memory implementations are provided. In the future, an
12//! error-injectable shim around the in-memory file system will be provided to help trigger
13//! filesystem errors in unit tests.
14//!
15//! The intent of this crate is for you to use the generic [`rsfs::GenFS`] everywhere where you use
16//! `std::fs` in your code. Your `main.rs` can use [`rsfs::disk::FS`] to get default disk behavior
17//! while your tests use `rsfs::mem::test::FS` (once it exists) to get an in-memory filesystem that
18//! can have errors injected.
19//!
20//! # An in-memory filesystem
21//!
22//! There existed no complete in-process in-memory filesystem when I wrote this crate; the
23//! implementation in [`rsfs::mem`] should suffice most needs.
24//!
25//! `rsfs::mem` is a platform specific module that `pub use`s the proper module based off the
26//! builder's platform. To get a platform agnostic module, you need to use the in-memory platform
27//! you desire. Thus, if you use [`rsfs::mem::unix`], you will get an in-memory system that follows
28//! Unix semantics. If you use `rsfs::mem::windows`, you will get an in-memory system that follows
29//! Windows semantics (however, you would have to write that module first).
30//!
31//! This means that `rsfs::mem` aims to essentially be an in-memory drop in for `std::fs` and
32//! forces you to structure your code in a cross-platform way. `rsfs::mem::unix` aims to be a Unix
33//! specific drop in that buys you Unix semantics on all platforms.
34//!
35//! # Caveats
36//!
37//! The current in-memory filesystems are only implemented for Unix. This means that the only
38//! cross-platform in-memory filesystem is specifically `rsfs::mem::unix`. Window's users can help
39//! by implementing the in-memory analog for Windows.
40//!
41//! The in-memory filesystem is implemented using some unsafe code. I deemed this necessary after
42//! working with the recursive data structure that is a filesystem through an `Arc`/`RwLock` for
43//! too long. The code is pretty well tested; there should be no problems. The usage of unsafe, in
44//! my opinion, makes the code much clearer, but it did require special care in some functions.
45//!
46//! # Documentation credit
47//!
48//! This crate copies _a lot_ of the documentation and examples that currently exist in `std::fs`.
49//! It not only makes it easier for people to migrate straight to this crate, but makes this crate
50//! much more understandable. This crate includes Rust's MIT license in its repo for further
51//! attribution purposes.
52//!
53//! [`std::fs`]: https://doc.rust-lang.org/std/fs/
54//! [`rsfs::GenFS`]: trait.GenFS.html
55//! [`rsfs::disk::FS`]: disk/struct.FS.html
56//! [`rsfs::mem`]: mem/index.html
57//! [`rsfs::mem::unix`]: mem/unix/index.html
58
59mod fs;
60pub use fs::*;
61
62pub mod disk;
63pub mod mem;
64pub mod unix_ext;
65
66mod errors;
67mod path_parts;
68mod ptr;