Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetReader is missing in the upgrade guides #1047

Open
nablabla opened this issue Feb 22, 2024 · 0 comments
Open

AssetReader is missing in the upgrade guides #1047

nablabla opened this issue Feb 22, 2024 · 0 comments

Comments

@nablabla
Copy link

nablabla commented Feb 22, 2024

How can Bevy's documentation be improved?

in any of the following (not sure which)
https://bevyengine.org/learn/migration-guides/0-10-to-0-11/
https://bevyengine.org/learn/migration-guides/0-11-to-0-12/
https://bevyengine.org/learn/migration-guides/0-12-to-0-13/
there is missing the 'AssetReader'
It was completely changed since 0.10.0
See here: https://bevyengine.org/examples/Assets/custom-asset-reader/
formerly it was called AssetIo
Also the signature of the read function changed:

xpected `{async block@src\asset_server_plugin.rs:53:23: 66:5}` to be a future that resolves to `Result<Box<dyn AsyncRead + Send + Sync + Unpin>, AssetReaderError>`, but it resolves to `Result<Vec<u8>, AssetReaderError>`

It is now in WASM the same as in non-WASM

Sorry if I ask, but it took me 3 weeks to get this implemented. I am relatively new to rust and had too read into assosiated types, Send, async, Pin, move, Futures, Javascript closures, the whole bindgen and web-assembly topics
If there is someone who can help me how I adopt my read function in impl AssetReader for CustomAssetReader:

    fn read<'a>(&'a self,path: &'a Path) -> BoxedFuture<'a, Result<Box<Reader<'a>>, AssetReaderError>>	{
		// if we are on wasm then get asset by ID from asset server
		#[cfg(target_arch = "wasm32")] {
			let result = load_asset(path);
			let res = Box::pin(async move {
				// Call the asynchronous function directly
				let result = result.await;
				result.map(|data| {
						let d = data.unwrap_or_else(|| Vec::<u8>::new());
						log::info!("unwrapped: {}", data_to_string(&d));
						d
					}) // Handle None case if needed
					.map_err(|error| {
						log::info!("map-error!!!!!!!! {:?}", error);
						AssetReaderError::NotFound(path_str.into())
					})		});
			return res;
		}

This worked in bevy 0.10.0 (with the old function name of course)
It now gives me the above error, so I understand that it (something) has to implement "AsyncRead + Send + Sync + Unpin". But I don't know how. Back then I asked on the discord server but never got any anwer

@alice-i-cecile alice-i-cecile transferred this issue from bevyengine/bevy Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants