vfs: Add stub MemoryBackend

This commit is contained in:
Lucien Greathouse
2020-02-19 23:35:45 -08:00
parent 00a29bb6be
commit 6322c1f46d
2 changed files with 79 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
mod memory_backend;
mod noop_backend;
mod std_backend;
@@ -5,6 +6,7 @@ use std::io;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
pub use memory_backend::MemoryBackend;
pub use noop_backend::NoopBackend;
pub use std_backend::StdBackend;
@@ -13,6 +15,7 @@ mod sealed {
pub trait Sealed {}
impl Sealed for MemoryBackend {}
impl Sealed for NoopBackend {}
impl Sealed for StdBackend {}
}

76
vfs/src/memory_backend.rs Normal file
View File

@@ -0,0 +1,76 @@
use std::io;
use std::path::Path;
use crate::{Metadata, ReadDir, VfsBackend, VfsEvent};
/// `VfsBackend` that reads from an in-memory filesystem.
#[non_exhaustive]
pub struct MemoryBackend;
impl MemoryBackend {
pub fn new() -> Self {
Self
}
}
impl VfsBackend for MemoryBackend {
fn read(&mut self, _path: &Path) -> io::Result<Vec<u8>> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn write(&mut self, _path: &Path, _data: &[u8]) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn read_dir(&mut self, _path: &Path) -> io::Result<ReadDir> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn remove_file(&mut self, _path: &Path) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn remove_dir_all(&mut self, _path: &Path) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn metadata(&mut self, _path: &Path) -> io::Result<Metadata> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn event_receiver(&self) -> crossbeam_channel::Receiver<VfsEvent> {
crossbeam_channel::never()
}
fn watch(&mut self, _path: &Path) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
fn unwatch(&mut self, _path: &Path) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Other,
"MemoryBackend doesn't do anything",
))
}
}