Struct FileReader

Source
pub struct FileReader { /* private fields */ }
Expand description

File reading utility.

Can be used for both asynchronous and synchronous reads, as long as they’re read in the same order they were queued up.

Implementations§

Source§

impl FileReader

Source

pub fn new( arena: &'static LinearAllocator<'_>, file: FileHandle, staging_buffer_size: usize, queue_capacity: usize, ) -> Option<FileReader>

Creates a new FileReader for reading file, with a maximum of queue_capacity concurrent read operations.

Source

pub fn staging_buffer_size(&self) -> usize

Returns the size of the staging buffer where file read operations write to, i.e. the size of the largest read supported by this file reader.

Source

pub fn push_read(&mut self, first_byte: u64, size: usize) -> bool

Queues up a read operation starting at first_byte, reading size bytes. Returns true if the request fit in the queue.

If size is larger than FileReader::staging_buffer_size, this will always return false.

Source

pub fn dispatch_reads(&mut self, platform: &dyn Platform)

Starts file read operations for the queued up loading requests.

Source

pub fn pop_read<T, F>( &mut self, platform: &dyn Platform, blocking: bool, use_result: F, ) -> Result<T, FileReadError>
where F: FnOnce(&mut [u8]) -> T,

Finishes the read operation at the front of the queue, and passes the results to the closure if the read was successful.

If blocking is true and FileReader::dispatch_reads has not been called, this will call it for convenience.

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.