vfs/
lib.rs

1//! Virtual file system abstraction
2//!
3//! The virtual file system abstraction generalizes over file systems and allow using
4//! different VirtualFileSystem implementations (i.e. an in memory implementation for unit tests)
5//!
6//! The main interaction with the virtual filesystem is by using virtual paths ([`VfsPath`](path/struct.VfsPath.html)).
7//!
8//! This crate currently has the following implementations:
9//!
10//!  * **[`PhysicalFS`](impls/physical/struct.PhysicalFS.html)** - the actual filesystem of the underlying OS
11//!  * **[`MemoryFS`](impls/memory/struct.MemoryFS.html)** - an ephemeral in-memory implementation (intended for unit tests)
12//!  * **[`AltrootFS`](impls/altroot/struct.AltrootFS.html)** - a file system with its root in a particular directory of another filesystem
13//!  * **[`OverlayFS`](impls/overlay/struct.OverlayFS.html)** - a union file system consisting of a read/writable upper layer and several read-only lower layers
14//!  * **[`EmbeddedFS`](impls/embedded/struct.EmbeddedFs.html)** - a read-only file system embedded in the executable, requires `embedded-fs` feature
15//!
16//! # Usage Examples
17//!
18//! ```
19//! use vfs::{VfsPath, PhysicalFS, VfsError};
20//!
21//! # fn main() -> vfs::VfsResult<()> {
22//! let root: VfsPath = PhysicalFS::new(std::env::current_dir().unwrap()).into();
23//! assert!(root.exists()?);
24//!
25//! let mut content = String::new();
26//! root.join("README.md")?.open_file()?.read_to_string(&mut content)?;
27//! assert!(content.contains("vfs"));
28//! # Ok::<(), VfsError>(())
29//! # }
30//! ```
31//!
32//! ```
33//! use vfs::{VfsPath, VfsError, MemoryFS};
34//!
35//! # fn main() -> vfs::VfsResult<()> {
36//! let root: VfsPath = MemoryFS::new().into();
37//! let path = root.join("test.txt")?;
38//! assert!(!path.exists()?);
39//!
40//! path.create_file()?.write_all(b"Hello world")?;
41//! assert!(path.exists()?);
42//! let mut content = String::new();
43//! path.open_file()?.read_to_string(&mut content)?;
44//! assert_eq!(content, "Hello world");
45//! # Ok::<(), VfsError>(())
46//! # }
47//! ```
48//!
49//!
50#![allow(unknown_lints)]
51#![allow(clippy::upper_case_acronyms)]
52#![allow(clippy::redundant_async_block)]
53#![allow(clippy::type_complexity)]
54
55#[cfg(any(test, feature = "export-test-macros"))]
56#[macro_use]
57pub mod test_macros;
58
59pub mod error;
60pub mod filesystem;
61pub mod impls;
62pub mod path;
63
64#[cfg(feature = "async-vfs")]
65pub mod async_vfs;
66
67pub use error::{VfsError, VfsResult};
68pub use filesystem::FileSystem;
69pub use impls::altroot::AltrootFS;
70#[cfg(feature = "embedded-fs")]
71pub use impls::embedded::EmbeddedFS;
72pub use impls::memory::MemoryFS;
73pub use impls::overlay::OverlayFS;
74pub use impls::physical::PhysicalFS;
75pub use path::*;