[−][src]Trait mruby_vfs::FileSystem
Provides standard file system operations.
Associated Types
Loading content...Required methods
fn current_dir(&self) -> Result<PathBuf>
Returns the current working directory.
This is based on std::env::current_dir.
fn set_current_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Updates the current working directory.
This is based on std::env::set_current_dir.
fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
Determines whether the path exists and points to a directory.
fn is_file<P: AsRef<Path>>(&self, path: P) -> bool
Determines whether the path exists and points to a file.
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Creates a new directory.
This is based on std::fs::create_dir.
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Recursively creates a directory and any missing parents.
This is based on std::fs::create_dir.
fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes an empty directory.
This is based on std::fs::remove_dir.
fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes a directory and any child files or directories.
This is based on std::fs::remove_dir_all.
fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Self::ReadDir>
Returns an iterator over the entries in a directory.
This is based on std::fs::read_dir.
fn create_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
Writes buf to a new file at path.
Errors
- A file or directory already exists at
path. - The parent directory of
pathdoes not exist. - Current user has insufficient permissions.
fn write_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
Writes buf to a new or existing file at buf.
This will overwrite any contents that already exist.
Errors
- The parent directory of
pathdoes not exist. - Current user has insufficient permissions.
fn overwrite_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
Writes buf to an existing file at buf.
This will overwrite any contents that already exist.
Errors
- No file
filedoes not exist. - The node at
fileis a directory. - Current user has insufficient permissions.
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>
Returns the contents of path.
Errors
pathdoes not exist.pathis a directory.- Current user has insufficient permissions.
fn read_file_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String>
Returns the contents of path as a string.
Errors
pathdoes not exist.pathis a directory.- Current user has insufficient permissions.
- Contents are not valid UTF-8
fn read_file_into<P, B>(&self, path: P, buf: B) -> Result<usize> where
P: AsRef<Path>,
B: AsMut<Vec<u8>>,
P: AsRef<Path>,
B: AsMut<Vec<u8>>,
Writes the contents of path into the buffer. If successful, returns
the number of bytes that were read.
Errors
pathdoes not exist.pathis a directory.- Current user has insufficient permissions.
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Removes the file at path.
This is based on std::fs::remove_file.
fn copy_file<P, Q>(&self, from: P, to: Q) -> Result<()> where
P: AsRef<Path>,
Q: AsRef<Path>,
P: AsRef<Path>,
Q: AsRef<Path>,
Copies the file at path from to the path to.
This is based on std::fs::copy.
fn rename<P, Q>(&self, from: P, to: Q) -> Result<()> where
P: AsRef<Path>,
Q: AsRef<Path>,
P: AsRef<Path>,
Q: AsRef<Path>,
Renames a file or directory.
If both from and to are files, to will be replaced.
Based on std::fs::rename.
fn readonly<P: AsRef<Path>>(&self, path: P) -> Result<bool>
Returns true if path is a readonly file.
Errors
pathdoes not exist.- Current user has insufficient permissions.
fn set_readonly<P: AsRef<Path>>(&self, path: P, readonly: bool) -> Result<()>
Sets or unsets the readonly flag of path.
Errors
pathdoes not exist.- Current user has insufficient permissions.
fn len<P: AsRef<Path>>(&self, path: P) -> u64
Returns the length of the node at the path or 0 if the node does not exist.
fn metadata<P: AsRef<Path>>(&self, path: P) -> Option<Self::Metadata>
Read metadata of path.
If path does not exist, return None. If path is a directory, return
None. If path has no metadata, return None.
fn set_metadata<P: AsRef<Path>>(
&self,
path: P,
metadata: Self::Metadata
) -> Result<()>
&self,
path: P,
metadata: Self::Metadata
) -> Result<()>
Implementors
impl<Metadata: Clone> FileSystem for FileSystem<Metadata>[src]
type DirEntry = DirEntry
type ReadDir = ReadDir
type Metadata = Metadata
fn current_dir(&self) -> Result<PathBuf>[src]
fn set_current_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool[src]
fn is_file<P: AsRef<Path>>(&self, path: P) -> bool[src]
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Self::ReadDir>[src]
fn create_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>, [src]
P: AsRef<Path>,
B: AsRef<[u8]>,
fn write_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>, [src]
P: AsRef<Path>,
B: AsRef<[u8]>,
fn overwrite_file<P, B>(&self, path: P, buf: B) -> Result<()> where
P: AsRef<Path>,
B: AsRef<[u8]>, [src]
P: AsRef<Path>,
B: AsRef<[u8]>,
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>[src]
fn read_file_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String>[src]
fn read_file_into<P, B>(&self, path: P, buf: B) -> Result<usize> where
P: AsRef<Path>,
B: AsMut<Vec<u8>>, [src]
P: AsRef<Path>,
B: AsMut<Vec<u8>>,
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]
fn copy_file<P, Q>(&self, from: P, to: Q) -> Result<()> where
P: AsRef<Path>,
Q: AsRef<Path>, [src]
P: AsRef<Path>,
Q: AsRef<Path>,
fn rename<P, Q>(&self, from: P, to: Q) -> Result<()> where
P: AsRef<Path>,
Q: AsRef<Path>, [src]
P: AsRef<Path>,
Q: AsRef<Path>,
fn readonly<P: AsRef<Path>>(&self, path: P) -> Result<bool>[src]
fn set_readonly<P: AsRef<Path>>(&self, path: P, readonly: bool) -> Result<()>[src]
fn len<P: AsRef<Path>>(&self, path: P) -> u64[src]
fn metadata<P: AsRef<Path>>(&self, path: P) -> Option<Self::Metadata>[src]
fn set_metadata<P: AsRef<Path>>(
&self,
path: P,
metadata: Self::Metadata
) -> Result<()>[src]
&self,
path: P,
metadata: Self::Metadata
) -> Result<()>