pub struct ExtractAssetFetch { /* private fields */ }Expand description
A handler for asset extraction that implements AssetFetch.
This struct is used to define the extraction logic for assets awaiting extraction from storage.
Implementations§
Source§impl ExtractAssetFetch
impl ExtractAssetFetch
Sourcepub fn new(
extract: impl FnMut(Entity, AssetPath<'_>, &World, &mut CommandBuffer) -> Result<(), Box<dyn Error>> + Send + Sync + 'static,
) -> Self
pub fn new( extract: impl FnMut(Entity, AssetPath<'_>, &World, &mut CommandBuffer) -> Result<(), Box<dyn Error>> + Send + Sync + 'static, ) -> Self
Creates a new ExtractAssetFetch instance.
§Arguments
extract: A function that performs asset extraction.
§Returns
A new ExtractAssetFetch instance.
Examples found in repository?
examples/16_extract_from_asset.rs (lines 30-39)
12fn main() -> Result<(), Box<dyn Error>> {
13 /* ANCHOR: main */
14 let mut database = AssetDatabase::default()
15 .with_protocol(TextAssetProtocol)
16 .with_protocol(BytesAssetProtocol)
17 // We start with regular fetch engine.
18 .with_fetch(FileAssetFetch::default().with_root("resources"));
19
20 // Start loading package ZIP bytes.
21 database.ensure("bytes://package.zip")?;
22
23 // Maintain database while busy.
24 while database.is_busy() {
25 database.maintain()?;
26 }
27
28 // Then we push extraction asset fetch to fetch engine stack. From now on
29 // any future asset request will be extracted from loaded ZIP archive.
30 database.push_fetch(ExtractAssetFetch::new(from_asset_extractor(
31 "bytes://package.zip",
32 |bytes: &Vec<u8>, path| {
33 let mut archive = ZipArchive::new(Cursor::new(bytes))?;
34 let mut file = archive.by_name(path.path())?;
35 let mut result = vec![];
36 file.read_to_end(&mut result)?;
37 Ok(result)
38 },
39 )));
40
41 // Extract some assets from ZIP asset.
42 let lorem = database.ensure("text://lorem.txt")?;
43 let trash = database.ensure("bytes://trash.bin")?;
44
45 // Run maintenance to process extracted asset bytes.
46 database.maintain()?;
47
48 println!("Lorem Ipsum: {}", lorem.access::<&String>(&database));
49 println!("Bytes: {:?}", trash.access::<&Vec<u8>>(&database));
50 /* ANCHOR_END: main */
51
52 Ok(())
53}Trait Implementations§
Source§impl AssetFetch for ExtractAssetFetch
impl AssetFetch for ExtractAssetFetch
Auto Trait Implementations§
impl Freeze for ExtractAssetFetch
impl !RefUnwindSafe for ExtractAssetFetch
impl Send for ExtractAssetFetch
impl Sync for ExtractAssetFetch
impl Unpin for ExtractAssetFetch
impl !UnwindSafe for ExtractAssetFetch
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
Mutably borrows from an owned value. Read more