Fs

Struct 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<Default>

Source

pub fn Default() -> Self

Creates default Fs without type parameter requirement.

Uses ZST api::Default.

Source§

impl Fs<Cache>

Source

pub fn Cached() -> Self

Creates Fs without type parameter requirement.

Uses api::Cache.

Source§

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

Source

pub fn new() -> Self

Source§

impl<Api: Api> Fs<Api>

Source

pub fn new_with(api: Api) -> Self

Source§

impl<Api: Api> Fs<Api>

Source

pub fn open<P: AsRef<Path>, Opts: OpenOptions>( &self, path: P, options: Opts, ) -> Result<File<Api>, ApiError>
where 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: Api, P: AsRef<Path>, Opts: OpenOptions>( &self, api: T, path: P, options: Opts, ) -> Result<File<T>, ApiError>

Open file for given options.

Creates new File instance with given api.

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

Source

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

Closes the given file.

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

Source

pub fn tell(&self, file: &mut impl AnyFile) -> Result<c_uint, 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: c_int, 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: c_uint, ) -> Result<c_uint, 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<c_uint, 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<c_uint, 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: AsRef<Path>>(&self, path: P) -> Result<FileStat, ApiError>

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

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

Source

pub fn metadata_to<P: AsRef<Path>>( &self, path: P, metadata: &mut FileStat, ) -> Result<(), ApiError>

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

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

Source

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

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: AsRef<Path>>(&self, path: P) -> Result<(), ApiError>

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: AsRef<Path>>(&self, path: P) -> Result<(), ApiError>

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: AsRef<Path>, Q: AsRef<Path>>( &self, from: P, to: Q, ) -> Result<(), ApiError>

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<(), ApiError>
where P: AsRef<Path>, 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> Clone for Fs<Api>

Source§

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

Returns a duplicate 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> Debug for Fs<Api>

Source§

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

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

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

Source§

fn default() -> Self

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

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

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

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.