forked from rojo-rbx/rojo
vfs: Add stub MemoryBackend
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
mod memory_backend;
|
||||||
mod noop_backend;
|
mod noop_backend;
|
||||||
mod std_backend;
|
mod std_backend;
|
||||||
|
|
||||||
@@ -5,6 +6,7 @@ use std::io;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
pub use memory_backend::MemoryBackend;
|
||||||
pub use noop_backend::NoopBackend;
|
pub use noop_backend::NoopBackend;
|
||||||
pub use std_backend::StdBackend;
|
pub use std_backend::StdBackend;
|
||||||
|
|
||||||
@@ -13,6 +15,7 @@ mod sealed {
|
|||||||
|
|
||||||
pub trait Sealed {}
|
pub trait Sealed {}
|
||||||
|
|
||||||
|
impl Sealed for MemoryBackend {}
|
||||||
impl Sealed for NoopBackend {}
|
impl Sealed for NoopBackend {}
|
||||||
impl Sealed for StdBackend {}
|
impl Sealed for StdBackend {}
|
||||||
}
|
}
|
||||||
|
|||||||
76
vfs/src/memory_backend.rs
Normal file
76
vfs/src/memory_backend.rs
Normal 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",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user