Reader

Trait Reader 

Source
pub trait Reader:
    AsyncRead
    + AsyncSeek
    + Unpin
    + Send
    + Sync {
    // Provided method
    fn read_to_end<'a>(
        &'a mut self,
        buf: &'a mut Vec<u8>,
    ) -> StackFuture<'a, Result<usize>, STACK_FUTURE_SIZE>  { ... }
}
Expand description

A type returned from AssetReader::read, which is used to read the contents of a file (or virtual file) corresponding to an asset.

This is essentially a trait alias for types implementing AsyncRead and AsyncSeek. The only reason a blanket implementation is not provided for applicable types is to allow implementors to override the provided implementation of Reader::read_to_end.

§Reader features

This trait includes super traits. However, this does not mean that your type needs to support every feature of those super traits. If the caller never uses that feature, then a dummy implementation that just returns an error is sufficient.

The caller can request a compatible Reader using ReaderRequiredFeatures (when using the AssetReader trait). This allows the caller to state which features of the reader it will use, avoiding cases where the caller uses a feature that the reader does not support.

For example, the caller may set ReaderRequiredFeatures::seek to SeekKind::AnySeek to indicate that they may seek backward, or from the start/end. A reader implementation may choose to support that, or may just detect those kinds of seeks and return an error.

Provided Methods§

Source

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> StackFuture<'a, Result<usize>, STACK_FUTURE_SIZE>

Reads the entire contents of this reader and appends them to a vec.

§Note for implementors

You should override the provided implementation if you can fill up the buffer more efficiently than the default implementation, which calls poll_read repeatedly to fill up the buffer 32 bytes at a time.

Trait Implementations§

Source§

impl Reader for Box<dyn Reader + '_>

Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> StackFuture<'a, Result<usize>, STACK_FUTURE_SIZE>

Reads the entire contents of this reader and appends them to a vec. Read more

Implementations on Foreign Types§

Source§

impl Reader for File

Source§

impl Reader for Box<dyn Reader + '_>

Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> StackFuture<'a, Result<usize>, STACK_FUTURE_SIZE>

Implementors§