Skip to main content

MtFile

Struct MtFile 

Source
pub struct MtFile;
Expand description

MT Framework’s file stream class (MtFile).

Wraps a game-side file object, exposing its I/O operations — open, read, write, seek and the various size/position queries — through the underlying vtable. Instances are created through the game’s own factory (see open), which is why the type derives CacheDti to locate its MtDti.

MtFile also implements core::fmt::Write, so it can be used as the target of write! / writeln! to append UTF-8 text.

§Layout

#[repr(C)] (an opaque, vtable-only type via #[derive(Object)]), since it is only ever used by reference to call its virtual functions.

Implementations§

Source§

impl MtFile

Source

pub fn open(path: &str, mode: OpenMode) -> MtResult<&mut Self>

Opens the file at path with the given OpenMode.

Locates the MtFile class, constructs a new instance through its factory, and opens the file on it. The path is passed to the game as a raw byte pointer.

§Errors

Returns MtError::DtiNotFound if the MtFile class is missing, MtError::FailedToCreateInstance if construction fails, or MtError::FailedToOpenFile if the open itself fails.

Source

pub fn read(&mut self, buffer: &mut [u8]) -> usize

Reads up to buffer.len() bytes into buffer, returning the number of bytes actually read.

Source

pub fn write(&mut self, data: &[u8]) -> usize

Writes data to the file, returning the number of bytes actually written.

Source

pub fn seek(&mut self, offset: isize, origin: Origin)

Moves the file position by offset bytes relative to origin.

Source

pub fn close(&mut self)

Source

pub fn is_async_reading(&self) -> bool

Source

pub fn tell(&self) -> usize

Source

pub fn size(&self) -> usize

Source

pub fn set_size(&mut self, size: usize)

Source

pub fn is_readable(&self) -> bool

Source

pub fn is_writable(&self) -> bool

Source

pub fn is_async_readable(&self) -> bool

Source

pub fn get_async_read_size(&self) -> usize

Trait Implementations§

Source§

impl CacheDti for MtFile

Source§

fn dti() -> Option<&'static MtDti>

Returns the MtDti describing this type’s class, if it exists.
Source§

impl HasVtable for MtFile

Source§

impl Object for MtFile

Source§

fn dtor(&mut self)

Runs the destructor on self
Source§

fn destroy(&mut self)

Runs the destructor on self and deallocates the object
Source§

fn create_ui(&self)

Invokes the object’s UI-creation virtual function (vtable slot 2).
Source§

fn is_enable_instance(&self) -> bool

Returns whether the object is currently an enabled instance (vtable slot 3).
Source§

fn create_property(&self, props: *mut c_void)

Populates props (an MtPropertyList) with the object’s reflected properties (vtable slot 4). Read more
Source§

fn get_dti(&self) -> *const c_void

Returns a raw pointer to the object’s MtDti (vtable slot 5). Read more
Source§

impl Write for MtFile

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.