Struct Filesystem

Source
pub struct Filesystem { /* private fields */ }
Expand description

A structure that contains the filesystem state and cache.

Implementations§

Source§

impl Filesystem

Source

pub fn new(id: &str, author: &str) -> Result<Filesystem>

Create a new Filesystem instance, using the given id and (on some platforms) the author as a portion of the user directory path. This function is called automatically by ggez, the end user should never need to call it.

Source

pub fn open<P: AsRef<Path>>(&mut self, path: P) -> Result<File>

Opens the given path and returns the resulting File in read-only mode.

Source

pub fn open_options<P: AsRef<Path>>( &mut self, path: P, options: OpenOptions, ) -> Result<File>

Opens a file in the user directory with the given filesystem::OpenOptions. Note that even if you open a file read-write, it can only write to files in the “user” directory.

Source

pub fn create<P: AsRef<Path>>(&mut self, path: P) -> Result<File>

Creates a new file in the user directory and opens it to be written to, truncating it if it already exists.

Source

pub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Create an empty directory in the user dir with the given name. Any parents to that directory that do not exist will be created.

Source

pub fn delete<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Deletes the specified file in the user dir.

Source

pub fn delete_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Deletes the specified directory in the user dir, and all its contents!

Source

pub fn exists<P: AsRef<Path>>(&self, path: P) -> bool

Check whether a file or directory exists.

Source

pub fn is_file<P: AsRef<Path>>(&self, path: P) -> bool

Check whether a path points at a file.

Source

pub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool

Check whether a path points at a directory.

Source

pub fn read_dir<P: AsRef<Path>>( &mut self, path: P, ) -> Result<Box<dyn Iterator<Item = PathBuf>>>

Returns a list of all files and directories in the resource directory, in no particular order.

Lists the base directory if an empty path is given.

Source

pub fn print_all(&mut self)

Prints the contents of all data directories to standard output. Useful for debugging.

Source

pub fn log_all(&mut self)

Outputs the contents of all data directories, using the “info” log level of the log crate. Useful for debugging.

Source

pub fn mount(&mut self, path: &Path, readonly: bool)

Adds the given (absolute) path to the list of directories it will search to look for resources.

You probably shouldn’t use this in the general case, since it is harder than it looks to make it bulletproof across platforms. But it can be very nice for debugging and dev purposes, such as by pushing $CARGO_MANIFEST_DIR/resources to it

Source

pub fn add_zip_file<R: Read + Seek + 'static>( &mut self, reader: R, ) -> Result<()>

Adds any object that implements Read + Seek as a zip file.

Note: This is not intended for system files for the same reasons as for .mount(). Rather, it can be used to read zip files from sources such as std::io::Cursor::new(includes_bytes!(...)) in order to embed resources into the game’s executable.

Trait Implementations§

Source§

impl Debug for Filesystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.