Struct playdate::fs::prelude::Fs

source ·
pub struct Fs<Api = Default>(/* private fields */);
Expand description

Playdate File-system API.

Uses inner api end-point for all operations.

Implementations§

source§

impl Fs

source

pub fn Default() -> Fs

Creates default Fs without type parameter requirement.

Uses ZST api::Default.

source§

impl Fs<Cache>

source

pub fn Cached() -> Fs<Cache>

Creates Fs without type parameter requirement.

Uses api::Cache.

source§

impl<Api> Fs<Api>
where Api: Default + Api,

source

pub fn new() -> Fs<Api>

source§

impl<Api> Fs<Api>
where Api: Api,

source

pub fn new_with(api: Api) -> Fs<Api>

source§

impl<Api> Fs<Api>
where Api: Api,

source

pub fn open<P, Opts>( &self, path: P, options: Opts ) -> Result<File<Api>, Error<Error>>
where P: AsRef<str>, Opts: OpenOptions, Api: Copy,

Open file for given options.

Creates new File instance with copy of inner api end-point.

Equivalent to sys::ffi::playdate_file::open

source

pub fn open_with<T, P, Opts>( &self, api: T, path: P, options: Opts ) -> Result<File<T>, Error<Error>>
where T: Api, P: AsRef<str>, Opts: OpenOptions,

Open file for given options.

Creates new File instance with given api.

Equivalent to sys::ffi::playdate_file::open

source

pub fn close<T>(&self, file: File<T>) -> Result<(), Error>
where T: Api,

Closes the given file.

Equivalent to sys::ffi::playdate_file::close

source

pub fn tell(&self, file: &mut impl AnyFile) -> Result<u32, Error>

Returns the current read/write offset in the given file.

Equivalent to sys::ffi::playdate_file::tell

source

pub fn seek_raw( &self, file: &mut impl AnyFile, pos: i32, whence: Whence ) -> Result<(), Error>

Sets the read/write offset in the given file to pos, relative to the whence.

Equivalent to sys::ffi::playdate_file::seek

source

pub fn read( &self, file: &mut impl AnyFile, to: &mut Vec<u8>, len: u32 ) -> Result<u32, Error>

Reads up to len bytes from the file into the buffer to.

Returns the number of bytes read (0 indicating end of file).

Caution: Vector must be prefilled with 0s.

let mut buf = Vec::<u8>::with_capacity(size);
buf.resize(size, 0);
fs.read(&mut file, &mut buf, size)?;

Equivalent to sys::ffi::playdate_file::read

source

pub fn write(&self, file: &mut impl AnyFile, from: &[u8]) -> Result<u32, Error>

Writes the buffer of bytes buf to the file.

Returns the number of bytes written.

Equivalent to sys::ffi::playdate_file::write

source

pub fn flush(&self, file: &mut impl AnyFile) -> Result<u32, Error>

Flushes the output buffer of file immediately.

Returns the number of bytes written.

Equivalent to sys::ffi::playdate_file::flush

source

pub fn metadata<P>(&self, path: P) -> Result<FileStat, Error<Error>>
where P: AsRef<str>,

Populates the FileStat stat with information about the file at path.

Equivalent to sys::ffi::playdate_file::stat

source

pub fn metadata_to<P>( &self, path: P, metadata: &mut FileStat ) -> Result<(), Error<Error>>
where P: AsRef<str>,

Writes into the given metadata information about the file at path.

Equivalent to sys::ffi::playdate_file::stat

source

pub fn create_dir<P>(&self, path: P) -> Result<(), Error<Error>>
where P: AsRef<str>,

Creates the given path in the Data/<gameid> folder.

It does not create intermediate folders.

Equivalent to sys::ffi::playdate_file::mkdir

source

pub fn remove<P>(&self, path: P) -> Result<(), Error<Error>>
where P: AsRef<str>,

Deletes the file at path. Directory is a file too, definitely.

See also remove_dir_all.

Equivalent to sys::ffi::playdate_file::unlink

source

pub fn remove_dir_all<P>(&self, path: P) -> Result<(), Error<Error>>
where P: AsRef<str>,

Deletes the file at path.

If the path is a folder, this deletes everything inside the folder (including folders, folders inside those, and so on) as well as the folder itself.

Equivalent to sys::ffi::playdate_file::unlink

source

pub fn rename<P, Q>(&self, from: P, to: Q) -> Result<(), Error<Error>>
where P: AsRef<str>, Q: AsRef<str>,

Renames the file at from to to.

It will overwrite the file at to.

It does not create intermediate folders.

Equivalent to sys::ffi::playdate_file::rename

source

pub fn read_dir<P, Fn>( &self, path: P, callback: Fn, include_hidden: bool ) -> Result<(), Error<Error>>
where P: AsRef<str>, Fn: FnMut(String),

Calls the given callback function for every file at path.

Subfolders are indicated by a trailing slash ‘/’ in filename.

This method does not recurse into subfolders.

If include_hidden is set, files beginning with a period will be included; otherwise, they are skipped.

Returns error if no folder exists at path or it can’t be opened.

Equivalent to sys::ffi::playdate_file::listfiles

Trait Implementations§

source§

impl<Api> Clone for Fs<Api>
where Api: Clone,

source§

fn clone(&self) -> Fs<Api>

Returns a copy of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Api> Debug for Fs<Api>
where Api: Debug,

source§

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

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

impl<Api> Default for Fs<Api>
where Api: Default + Api,

source§

fn default() -> Fs<Api>

Returns the “default value” for a type. Read more
source§

impl<Api> Copy for Fs<Api>
where Api: Copy,

Auto Trait Implementations§

§

impl<Api> Freeze for Fs<Api>
where Api: Freeze,

§

impl<Api> RefUnwindSafe for Fs<Api>
where Api: RefUnwindSafe,

§

impl<Api> Send for Fs<Api>
where Api: Send,

§

impl<Api> Sync for Fs<Api>
where Api: Sync,

§

impl<Api> Unpin for Fs<Api>
where Api: Unpin,

§

impl<Api> UnwindSafe for Fs<Api>
where Api: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.