pub trait Reader:
AsyncRead
+ Unpin
+ Send
+ Sync {
// Required method
fn seekable(
&mut self,
) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError>;
// Provided method
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> StackFuture<'a, Result<usize, Error>, bevy_asset::::io::Reader::read_to_end::{constant#0}> ⓘ { ... }
}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.
Required Methods§
Sourcefn seekable(
&mut self,
) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError>
fn seekable( &mut self, ) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError>
Casts this Reader as a SeekableReader, which layers on AsyncSeek functionality.
Returns Ok if this Reader supports seeking. Otherwise returns Err.
Implementers of Reader are highly encouraged to provide this functionality, as it makes the
reader compatible with “seeking” AssetLoader implementations.
AssetLoader implementations that call this are encouraged to provide fallback behavior
when it fails, such as reading into a seek-able Vec (or AsyncSeek-able VecReader):
let mut fallback_reader;
let reader = match reader.seekable() {
Ok(seek) => seek,
Err(_) => {
fallback_reader = VecReader::new(Vec::new());
reader.read_to_end(&mut fallback_reader.bytes).await.unwrap();
&mut fallback_reader
}
};
reader.seek(SeekFrom::Start(10)).await.unwrap();Provided Methods§
Sourcefn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> StackFuture<'a, Result<usize, Error>, bevy_asset::::io::Reader::read_to_end::{constant#0}> ⓘ
fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> StackFuture<'a, Result<usize, Error>, bevy_asset::::io::Reader::read_to_end::{constant#0}> ⓘ
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.