Module vfs::async_vfs

source ·
Expand description

Asynchronous port of virtual file system abstraction

Just as with the synchronous version, the main interaction with the virtual filesystem is by using virtual paths (AsyncVfsPath).

This module currently has the following asynchronous file system implementations:

  • AsyncPhysicalFS - the actual filesystem of the underlying OS
  • AsyncMemoryFS - an ephemeral in-memory implementation (intended for unit tests)
  • AsyncAltrootFS - a file system with its root in a particular directory of another filesystem
  • AsyncOverlayFS - a union file system consisting of a read/writable upper layer and several read-only lower layers

§Usage Examples

use async_std::io::{ReadExt, WriteExt};
use vfs::async_vfs::{AsyncVfsPath, AsyncPhysicalFS};
use vfs::VfsError;

let root: AsyncVfsPath = AsyncPhysicalFS::new(std::env::current_dir().unwrap()).into();
assert!(root.exists().await?);

let mut content = String::new();
root.join("README.md")?.open_file().await?.read_to_string(&mut content).await?;
assert!(content.contains("vfs"));
use async_std::io::{ReadExt, WriteExt};
use vfs::async_vfs::{AsyncVfsPath, AsyncMemoryFS};
use vfs::VfsError;

let root: AsyncVfsPath = AsyncMemoryFS::new().into();
let path = root.join("test.txt")?;
assert!(!path.exists().await?);

path.create_file().await?.write_all(b"Hello world").await?;
assert!(path.exists().await?);
let mut content = String::new();
path.open_file().await?.read_to_string(&mut content).await?;
assert_eq!(content, "Hello world");

Re-exports§

Modules§

  • The async filesystem trait definitions needed to implement new async virtual filesystems
  • Async Virtual filesystem implementations
  • Virtual filesystem path