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
impl Fs
sourcepub fn Default() -> Fs
pub fn Default() -> Fs
Creates default Fs
without type parameter requirement.
Uses ZST api::Default
.
source§impl<Api> Fs<Api>where
Api: Api,
impl<Api> Fs<Api>where
Api: Api,
sourcepub fn open<P, Opts>(
&self,
path: P,
options: Opts
) -> Result<File<Api>, Error<Error>>where
P: AsRef<str>,
Opts: OpenOptions,
Api: Copy,
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
sourcepub 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,
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
sourcepub fn close<T>(&self, file: File<T>) -> Result<(), Error>where
T: Api,
pub fn close<T>(&self, file: File<T>) -> Result<(), Error>where
T: Api,
Closes the given file.
Equivalent to sys::ffi::playdate_file::close
sourcepub fn tell(&self, file: &mut impl AnyFile) -> Result<u32, Error>
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
sourcepub fn seek_raw(
&self,
file: &mut impl AnyFile,
pos: i32,
whence: Whence
) -> Result<(), Error>
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
.
Whence::Start
is relative to the beginning of the file,Whence::Current
is relative to the current position of the file,Whence::End
is relative to the end of the file.
Equivalent to sys::ffi::playdate_file::seek
sourcepub fn read(
&self,
file: &mut impl AnyFile,
to: &mut Vec<u8>,
len: u32
) -> Result<u32, Error>
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 0
s.
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
sourcepub fn write(&self, file: &mut impl AnyFile, from: &[u8]) -> Result<u32, Error>
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
sourcepub fn flush(&self, file: &mut impl AnyFile) -> Result<u32, Error>
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
sourcepub fn metadata<P>(&self, path: P) -> Result<FileStat, Error<Error>>where
P: AsRef<str>,
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
sourcepub fn metadata_to<P>(
&self,
path: P,
metadata: &mut FileStat
) -> Result<(), Error<Error>>where
P: AsRef<str>,
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
sourcepub fn create_dir<P>(&self, path: P) -> Result<(), Error<Error>>where
P: AsRef<str>,
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
sourcepub fn remove<P>(&self, path: P) -> Result<(), Error<Error>>where
P: AsRef<str>,
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
sourcepub fn remove_dir_all<P>(&self, path: P) -> Result<(), Error<Error>>where
P: AsRef<str>,
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
sourcepub fn rename<P, Q>(&self, from: P, to: Q) -> Result<(), Error<Error>>where
P: AsRef<str>,
Q: AsRef<str>,
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
sourcepub fn read_dir<P, Fn>(
&self,
path: P,
callback: Fn,
include_hidden: bool
) -> Result<(), Error<Error>>where
P: AsRef<str>,
Fn: FnMut(String),
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§
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
§impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
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.