sos_vfs/lib.rs
1#![allow(clippy::len_without_is_empty)]
2//! Virtual file system.
3//!
4//! The API is designed to match the `tokio::fs` module which in
5//! turn is based on `std::fs` so the API should be familiar.
6//!
7//! The default operating system VFS re-exports the
8//! `tokio::fs` module providing access to the operating system's
9//! file system.
10//!
11//! Using the memory VFS allows us to compile and target the
12//! `wasm32-unknown-unknown` platform with minimal changes to
13//! the code.
14//!
15//! The memory file system is enabled by default for
16//! `wasm32-unknown-unknown` or if the `mem-fs` feature
17//! is enabled.
18//!
19//! # Memory VFS Caveats
20//!
21//! Relative paths are resolved from the root of the file system.
22//!
23//! Avoid using the `PathBuf` functions `exists()`, `metadata()`,
24//! `is_dir()`, `is_file()` etc as they will be incorrect when
25//! using a virtual file system. Instead use the `vfs::metadata()` and
26//! `vfs::try_exists()` asynchronous functions.
27//!
28//! The `SystemTime` type is not available on `wasm32-unknown-unknwown`
29//! so `Metadata` does not support `created()`, `accessed()`
30//! and `modified()` for that target.
31//!
32//! # Memory VFS Unsupported
33//!
34//! This functionality is not supported yet but we hope to
35//! implement in the future.
36//!
37//! The `readonly` flag on permissions is not supported yet.
38//!
39//! Created, accessed and modified times are not set
40//! yet for non-webassembly targets that support `SystemTime`.
41//!
42//! Symbolic links are not supported yet which means the `hard_link()`,
43//! `symlink()`, `symlink_metadata()`, `symlink_file()` and
44//! `symlink_dir()` functions are not available.
45//!
46
47#[cfg(any(
48 feature = "mem-fs",
49 all(target_arch = "wasm32", target_os = "unknown")
50))]
51mod memory;
52
53#[cfg(any(
54 feature = "mem-fs",
55 all(target_arch = "wasm32", target_os = "unknown")
56))]
57pub use memory::*;
58
59#[cfg(all(
60 not(all(target_arch = "wasm32", target_os = "unknown")),
61 not(feature = "mem-fs")
62))]
63mod os;
64
65#[cfg(all(
66 not(all(target_arch = "wasm32", target_os = "unknown")),
67 not(feature = "mem-fs")
68))]
69#[allow(unused_imports)]
70pub use os::*;
71
72#[cfg(test)]
73mod tests;