pub struct EmbeddedAssetReader { /* private fields */ }
Expand description
Struct which can be used to retrieve embedded assets directly
without the normal Bevy Handle<T>
approach. This is useful
for cases where you need an asset outside the Bevy ECS environment.
This is only available when the default-source
cargo feature is enabled.
Example usage is below which assumes you have an asset named image.png
in your assets
folder (which this crate embeds at compile time).
use bevy_embedded_assets::{DataReader, EmbeddedAssetReader};
use std::path::Path;
fn some_bevy_system() {
let embedded: EmbeddedAssetReader = EmbeddedAssetReader::preloaded();
let reader: DataReader = embedded.load_path_sync(&Path::new("image.png")).unwrap();
let image_data: Vec<u8> = reader.0.to_vec();
// Do what you need with the data
}
Implementations§
Source§impl EmbeddedAssetReader
impl EmbeddedAssetReader
Sourcepub fn preloaded() -> Self
pub fn preloaded() -> Self
Create an EmbeddedAssetReader
loaded with all the assets found by the build script.
This ensures the EmbeddedAssetReader
has all (embedded) assets loaded and can be used
directly without the typical Bevy Handle<T>
approach. Retrieve assets directly after
calling preloaded
with EmbeddedAssetReader::load_path_sync()
.
Sourcepub fn load_path_sync(
&self,
path: &Path,
) -> Result<DataReader, AssetReaderError>
pub fn load_path_sync( &self, path: &Path, ) -> Result<DataReader, AssetReaderError>
Get the data from the asset matching the path provided.
§Errors
This will returns an error if the path is not known.
Trait Implementations§
Source§impl AssetReader for EmbeddedAssetReader
impl AssetReader for EmbeddedAssetReader
Source§async fn read<'a>(
&'a self,
path: &'a Path,
) -> Result<impl Reader + 'a, AssetReaderError>
async fn read<'a>( &'a self, path: &'a Path, ) -> Result<impl Reader + 'a, AssetReaderError>
Source§async fn read_meta<'a>(
&'a self,
path: &'a Path,
) -> Result<impl Reader + 'a, AssetReaderError>
async fn read_meta<'a>( &'a self, path: &'a Path, ) -> Result<impl Reader + 'a, AssetReaderError>
Source§async fn read_directory<'a>(
&'a self,
path: &'a Path,
) -> Result<Box<PathStream>, AssetReaderError>
async fn read_directory<'a>( &'a self, path: &'a Path, ) -> Result<Box<PathStream>, AssetReaderError>
Source§async fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> Result<bool, AssetReaderError>
async fn is_directory<'a>( &'a self, path: &'a Path, ) -> Result<bool, AssetReaderError>
Source§fn read_meta_bytes<'a>(&'a self, path: &'a Path) -> impl ConditionalSendFuture
fn read_meta_bytes<'a>(&'a self, path: &'a Path) -> impl ConditionalSendFuture
path
into a Vec<u8>
. This is a convenience
function that wraps AssetReader::read_meta
by default.Source§impl Debug for EmbeddedAssetReader
impl Debug for EmbeddedAssetReader
Auto Trait Implementations§
impl Freeze for EmbeddedAssetReader
impl !RefUnwindSafe for EmbeddedAssetReader
impl Send for EmbeddedAssetReader
impl Sync for EmbeddedAssetReader
impl Unpin for EmbeddedAssetReader
impl !UnwindSafe for EmbeddedAssetReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> ErasedAssetReader for Twhere
T: AssetReader,
impl<T> ErasedAssetReader for Twhere
T: AssetReader,
Source§fn read<'a>(
&'a self,
path: &'a Path,
) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Reader + 'a>, AssetReaderError>> + 'a>>
fn read<'a>( &'a self, path: &'a Path, ) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Reader + 'a>, AssetReaderError>> + 'a>>
Source§fn read_meta<'a>(
&'a self,
path: &'a Path,
) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Reader + 'a>, AssetReaderError>> + 'a>>
fn read_meta<'a>( &'a self, path: &'a Path, ) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Reader + 'a>, AssetReaderError>> + 'a>>
Source§fn read_directory<'a>(
&'a self,
path: &'a Path,
) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Stream<Item = PathBuf> + Send + Unpin>, AssetReaderError>> + 'a>>
fn read_directory<'a>( &'a self, path: &'a Path, ) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Box<dyn Stream<Item = PathBuf> + Send + Unpin>, AssetReaderError>> + 'a>>
Source§fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<bool, AssetReaderError>> + 'a>>
fn is_directory<'a>( &'a self, path: &'a Path, ) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<bool, AssetReaderError>> + 'a>>
Source§fn read_meta_bytes<'a>(
&'a self,
path: &'a Path,
) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Vec<u8>, AssetReaderError>> + 'a>>
fn read_meta_bytes<'a>( &'a self, path: &'a Path, ) -> Pin<Box<dyn ConditionalSendFuture<Output = Result<Vec<u8>, AssetReaderError>> + 'a>>
path
into a Vec<u8>
. This is a convenience
function that wraps ErasedAssetReader::read_meta
by default.Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more