pub trait FileSystem {
// Required methods
fn metadata(&self, path: &Path) -> Result<Metadata>;
fn is_dir(&self, path: &Path) -> bool;
fn is_file(&self, path: &Path) -> bool;
fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>;
fn get_disks(&self, canonicalize_paths: bool) -> Disks;
fn is_path_hidden(&self, path: &Path) -> bool;
fn create_dir(&self, path: &Path) -> Result<()>;
fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories>;
fn current_dir(&self) -> Result<PathBuf>;
// Provided method
fn load_text_file_preview(
&self,
_path: &Path,
_max_chars: usize,
) -> Result<String> { ... }
}
Expand description
An abstraction over the host system, allowing the file dialog to be used to browse e.g. in memory filesystems.
§Examples
use egui_file_dialog::{FileDialog, FileSystem, UserDirectories, Metadata, Disks};
use std::{io, path::{Path, PathBuf}};
struct MyFileSystem;
impl FileSystem for MyFileSystem {
fn metadata(&self, path: &Path) -> io::Result<Metadata> { todo!() }
fn is_dir(&self, path: &Path) -> bool { todo!() }
fn is_file(&self, path: &Path) -> bool { todo!() }
fn read_dir(&self, path: &Path) -> io::Result<Vec<PathBuf>> { todo!() }
fn get_disks(&self, canonicalize_paths: bool) -> Disks { todo!() }
fn is_path_hidden(&self, path: &Path) -> bool { todo!() }
fn create_dir(&self, path: &Path) -> io::Result<()> { todo!() }
fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories> { todo!() }
fn current_dir(&self) -> io::Result<PathBuf> { Ok("/".into()) }
}
let dialog = FileDialog::with_file_system(std::sync::Arc::new(MyFileSystem));
/* Use the file dialog as usual */
Required Methods§
Determine if a path is hidden
Sourcefn create_dir(&self, path: &Path) -> Result<()>
fn create_dir(&self, path: &Path) -> Result<()>
Creates a new directory
Sourcefn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories>
fn user_dirs(&self, canonicalize_paths: bool) -> Option<UserDirectories>
Returns the user directories
Sourcefn current_dir(&self) -> Result<PathBuf>
fn current_dir(&self) -> Result<PathBuf>
Get the current working directory