From 6322c1f46de649da14d51486fee6656e761d5381 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 19 Feb 2020 23:35:45 -0800 Subject: [PATCH] vfs: Add stub MemoryBackend --- vfs/src/lib.rs | 3 ++ vfs/src/memory_backend.rs | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 vfs/src/memory_backend.rs diff --git a/vfs/src/lib.rs b/vfs/src/lib.rs index 40b8979c..27a31a9d 100644 --- a/vfs/src/lib.rs +++ b/vfs/src/lib.rs @@ -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 {} } diff --git a/vfs/src/memory_backend.rs b/vfs/src/memory_backend.rs new file mode 100644 index 00000000..d16cdd04 --- /dev/null +++ b/vfs/src/memory_backend.rs @@ -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> { + 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 { + 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 { + Err(io::Error::new( + io::ErrorKind::Other, + "MemoryBackend doesn't do anything", + )) + } + + fn event_receiver(&self) -> crossbeam_channel::Receiver { + 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", + )) + } +}