Struct ggez::filesystem::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<P: AsRef<Path>, Q: AsRef<Path>>( id: &str, author: &str, resources_dir_name: P, resources_zip_name: Q ) -> GameResult<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>>(&self, path: P) -> GameResult<File>

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

source

pub fn open_options<P: AsRef<Path>>( &self, path: P, options: OpenOptions ) -> GameResult<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>>(&self, path: P) -> GameResult<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>>(&self, path: P) -> GameResult

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>>(&self, path: P) -> GameResult

Deletes the specified file in the user dir.

source

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

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>>( &self, path: P ) -> GameResult<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(&self)

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

source

pub fn log_all(&self)

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

source

pub fn mount(&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>(&self, reader: R) -> GameResult

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.

source

pub fn read_config(&self) -> GameResult<Conf>

Looks for a file named /conf.toml in any resource directory and loads it if it finds it. If it can’t read it for some reason, returns an error.

source

pub fn write_config(&self, conf: &Conf) -> GameResult

Takes a Conf object and saves it to the user directory, overwriting any file already there.

source

pub fn resources_dir(&self) -> &Path

Returns the full path to the resource directory (even if it doesn’t exist)

source

pub fn zip_dir(&self) -> &Path

Get a reference to the filesystem’s zip dir.

source

pub fn user_config_dir(&self) -> &Path

Return the full path to the user config directory.

source

pub fn user_data_dir(&self) -> &Path

Return the full path to the user data directory.

Trait Implementations§

source§

impl Debug for Filesystem

source§

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

Formats the value using the given formatter. Read more
source§

impl Has<Filesystem> for Context

source§

fn retrieve(&self) -> &Filesystem

Method to retrieve the context type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

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

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,