SDL_IOStreamInterface

Struct SDL_IOStreamInterface 

Source
#[repr(C)]
pub struct SDL_IOStreamInterface { pub version: Uint32, pub size: Option<unsafe extern "C" fn(userdata: *mut c_void) -> Sint64>, pub seek: Option<unsafe extern "C" fn(userdata: *mut c_void, offset: Sint64, whence: SDL_IOWhence) -> Sint64>, pub read: Option<unsafe extern "C" fn(userdata: *mut c_void, ptr: *mut c_void, size: usize, status: *mut SDL_IOStatus) -> usize>, pub write: Option<unsafe extern "C" fn(userdata: *mut c_void, ptr: *const c_void, size: usize, status: *mut SDL_IOStatus) -> usize>, pub flush: Option<unsafe extern "C" fn(userdata: *mut c_void, status: *mut SDL_IOStatus) -> bool>, pub close: Option<unsafe extern "C" fn(userdata: *mut c_void) -> bool>, }
Expand description

The function pointers that drive an SDL_IOStream.

Applications can provide this struct to SDL_OpenIO() to create their own implementation of SDL_IOStream. This is not necessarily required, as SDL already offers several common types of I/O streams, via functions like SDL_IOFromFile() and SDL_IOFromMem().

This structure should be initialized using SDL_INIT_INTERFACE()

§Availability

This struct is available since SDL 3.2.0.

§See also

§Notes for sdl3-sys

This interface struct can be initialized with SDL_IOStreamInterface::new() or Default::default().

Fields§

§version: Uint32§size: Option<unsafe extern "C" fn(userdata: *mut c_void) -> Sint64>

Return the number of bytes in this SDL_IOStream

\return the total size of the data stream, or -1 on error.

§seek: Option<unsafe extern "C" fn(userdata: *mut c_void, offset: Sint64, whence: SDL_IOWhence) -> Sint64>

Seek to offset relative to whence, one of stdio’s whence values: SDL_IO_SEEK_SET, SDL_IO_SEEK_CUR, SDL_IO_SEEK_END

\return the final offset in the data stream, or -1 on error.

§read: Option<unsafe extern "C" fn(userdata: *mut c_void, ptr: *mut c_void, size: usize, status: *mut SDL_IOStatus) -> usize>

Read up to size bytes from the data stream to the area pointed at by ptr. size will always be > 0.

On an incomplete read, you should set *status to a value from the SDL_IOStatus enum. You do not have to explicitly set this on a complete, successful read.

\return the number of bytes read

§write: Option<unsafe extern "C" fn(userdata: *mut c_void, ptr: *const c_void, size: usize, status: *mut SDL_IOStatus) -> usize>

Write exactly size bytes from the area pointed at by ptr to data stream. size will always be > 0.

On an incomplete write, you should set *status to a value from the SDL_IOStatus enum. You do not have to explicitly set this on a complete, successful write.

\return the number of bytes written

§flush: Option<unsafe extern "C" fn(userdata: *mut c_void, status: *mut SDL_IOStatus) -> bool>

If the stream is buffering, make sure the data is written out.

On failure, you should set *status to a value from the SDL_IOStatus enum. You do not have to explicitly set this on a successful flush.

\return true if successful or false on write error when flushing data.

§close: Option<unsafe extern "C" fn(userdata: *mut c_void) -> bool>

Close and free any allocated resources.

This does not guarantee file writes will sync to physical media; they can be in the system’s file cache, waiting to go to disk.

The SDL_IOStream is still destroyed even if this fails, so clean up anything even if flushing buffers, etc, returns an error.

\return true if successful or false on write error when flushing data.

Implementations§

Source§

impl SDL_IOStreamInterface

Source

pub const fn new() -> Self

Create a new SDL_IOStreamInterface initialized with SDL_INIT_INTERFACE

Trait Implementations§

Source§

impl Debug for SDL_IOStreamInterface

Source§

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

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

impl Default for SDL_IOStreamInterface

Source§

fn default() -> Self

Create a new SDL_IOStreamInterface initialized with SDL_INIT_INTERFACE

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.