Filesystem

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<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 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn to_sample_(self) -> U

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

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

fn vzip(self) -> V

Source§

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