fetcher.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. use std::{
  2. io,
  3. path::{Path, PathBuf},
  4. };
  5. use crossbeam_channel::Receiver;
  6. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  7. pub enum FileType {
  8. File,
  9. Directory,
  10. }
  11. // TODO: Use our own event type instead of notify's.
  12. pub type ImfsEvent = notify::DebouncedEvent;
  13. /// The generic interface that `Imfs` uses to lazily read files from the disk.
  14. /// In tests, it's stubbed out to do different versions of absolutely nothing
  15. /// depending on the test.
  16. pub trait ImfsFetcher {
  17. fn file_type(&mut self, path: &Path) -> io::Result<FileType>;
  18. fn read_children(&mut self, path: &Path) -> io::Result<Vec<PathBuf>>;
  19. fn read_contents(&mut self, path: &Path) -> io::Result<Vec<u8>>;
  20. fn create_directory(&mut self, path: &Path) -> io::Result<()>;
  21. fn write_file(&mut self, path: &Path, contents: &[u8]) -> io::Result<()>;
  22. fn remove(&mut self, path: &Path) -> io::Result<()>;
  23. fn watch(&mut self, path: &Path);
  24. fn unwatch(&mut self, path: &Path);
  25. fn receiver(&self) -> Receiver<ImfsEvent>;
  26. }