| Crates.io | floppy-disk |
| lib.rs | floppy-disk |
| version | 0.2.6 |
| created_at | 2023-03-16 17:19:35.181116+00 |
| updated_at | 2023-07-19 23:35:46.151153+00 |
| description | async filesystem facade for rust! |
| homepage | |
| repository | https://github.com/queer/floppy-disk |
| max_upload_size | |
| id | 811676 |
| size | 51,194 |
floppy disk is a WIP, async-only filesystem facade for Rust.
Have you ever worked with std::fs? tokio::fs? Then you've probably realised
that testing filesystem code is difficult and sometimes scary. Is that
fs::remove_dir_all really safe to run?
The point of floppy disk is to fix this. Rather than always using the real
filesystem, floppy disk lets you choose a backend for your filesystem access,
via the FloppyDisk trait. Current implementations include in-memory and real
filesystem via Tokio. This way, you can use the real filesystem when you need,
but have your tests hit a fake in-memory filesystem instead.
FloppyDisk traitMemFile
implementing Read/Write/Seek, but this is mostly a hack to make
working with sync-only external libraries (ex. ar) easier.floppy disk attempts to recreate the std::fs API 1:1, with the caveat of
being async-only.
let fs = ...; // MemFloppyDisk::new() | TokioFloppyDisk::new()
fs.create_dir_all("/foo/bar").await?;
fs.write("/foo/bar/baz.txt", b"hello world").await?;
let contents = fs.read_to_string("/foo/bar/baz.txt").await?;
assert_eq!(contents, "hello world");
Passing a FloppyDisk around:
struct MyStruct<'a, F: FloppyDisk<'a>> {
fs: F,
_marker: PhantomData<&'a ()>,
}
async fn my_fn<'a, F: FloppyDisk<'a>> {
// ...
}