Struct playdate_fs::file::File

source ·
pub struct File(/* private fields */);

Implementations§

source§

impl File

source

pub fn valid(&self) -> bool

source

pub fn open<P: AsRef<Path>>(path: P, data_dir: bool) -> Result<File, ApiError>

Attempts to open a file in read-only mode.

See the OpenOptions::open method for more details.

https://sdk.play.date/2.0.1/Inside%20Playdate%20with%20C.html#f-file.open

source

pub fn read( &mut self, to: &mut Vec<u8>, len: c_uint ) -> Result<c_uint, ApiError>

Reads up to len bytes from the file into the buffer buf. Returns the number of bytes read (0 indicating end of file).

Examples found in repository?
examples/simple.rs (line 74)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn read_file() -> Result<(), fs::error::ApiError> {
	let fs = fs::Fs::new()?;

	println!("reading file metadata");
	let info = fs.metadata(&FILE)?;
	println!("info: {info:?}");


	// prepare prefilled buffer:
	println!("preparing buffer for {} bytes", info.size);
	let mut buf = vec![0_u8; info.size as usize];

	let mut file = FileOptions::new().read(true)
	                                 .read_data(true)
	                                 .open_using(FILE, &fs)?;

	println!("reading '{FILE}'");
	let bytes_read = file.read(&mut buf, info.size)?;
	println!("read {bytes_read} bytes");

	let result = String::from_utf8(buf)?;
	println!("content:\n{result}");
	Ok(())
}
source

pub fn write(&mut self, from: &[u8]) -> Result<c_uint, ApiError>

Writes the buffer of bytes buf to the file. Returns the number of bytes written.

source

pub fn flush(&mut self) -> Result<c_uint, ApiError>

Flushes the output buffer of file immediately. Returns the number of bytes written.

source

pub fn tell(&mut self) -> Result<c_uint, ApiError>

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

source

pub fn seek(&mut self, pos: SeekFrom) -> Result<c_uint, ApiError>

Sets the read/write offset in the given file handle to pos, relative to the whence. Whence::Set is relative to the beginning of the file, Whence::Cur is relative to the current position of the file pointer, and Whence::End is relative to the end of the file. Returns 0 on success.

source

pub fn close(self) -> Result<(), ApiError>

Closes the this file handle.

source

pub fn options() -> impl OpenOptions + FileOptionsExt

Creates a blank new set of options ready for configuration. All options are initially set to false.

It is equivalent to FileOptions::new().

Trait Implementations§

source§

impl Drop for File

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for File

§

impl !Send for File

§

impl !Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.