pub unsafe trait FileSystemAsync: FileSystem {
// Required methods
fn read(info: AsyncReadInfo, userdata: *mut c_void) -> Result<()>;
fn cancel(info: AsyncCancelInfo, userdata: *mut c_void) -> Result<()>;
}
Expand description
An async filesystem.
§Safety
This trait is marked as unsafe because a correct implementation of FileSystemAsync
is hard to get right.
I’d suggest reading up on the FMOD documentation to get a better idea of how to write this.
Required Methods§
Sourcefn read(info: AsyncReadInfo, userdata: *mut c_void) -> Result<()>
fn read(info: AsyncReadInfo, userdata: *mut c_void) -> Result<()>
Callback for reading from a file asynchronously.
This callback allows you to accept a file I/O request without servicing it immediately.
The callback can queue or store the AsyncReadInfo
,
so that a ‘servicing routine’ can read the data and mark the job as done.
Marking an asynchronous job as ‘done’ outside of this callback can be done by calling AsyncReadInfo::finish
with the file read result as a parameter.
If the servicing routine is processed in the same thread as the thread that invokes this callback
(for example the thread that calls System::create_sound
or System::create_stream
),
a deadlock will occur because while System::create_sound
or System::create_stream
waits for the file data,
the servicing routine in the main thread won’t be able to execute.
This typically means an outside servicing routine should typically be run in a separate thread.
The read request can be queued or stored and this callback can return immediately with Ok
.
Returning an error at this point will cause FMOD to stop what it was doing and return back to the caller.
If it is from FMOD’s stream thread, the stream will typically stop.
Sourcefn cancel(info: AsyncCancelInfo, userdata: *mut c_void) -> Result<()>
fn cancel(info: AsyncCancelInfo, userdata: *mut c_void) -> Result<()>
Callback for cancelling a pending asynchronous read.
This callback is called to stop/release or shut down the resource that is holding the file, for example: releasing a Sound stream.
Before returning from this callback the implementation must ensure that all references to info are relinquished.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.