bevy_asset: support upgrading Reader to SeekableReader#22182
bevy_asset: support upgrading Reader to SeekableReader#22182cart merged 10 commits intobevyengine:mainfrom
Conversation
andriyDev
left a comment
There was a problem hiding this comment.
LGTM, but we need to delete the remnants: android, wasm, and web modules need to be cleaned up, custom_asset_reader example also need to be cleaned up. Also some migration guides we need to update (we can leave this until later).
I updated these (and release notes) right before you posted 😄 |
janhohenheim
left a comment
There was a problem hiding this comment.
Looks much cleaner to me, good job! The PR introduces some new public API that is missing documentation. Approving after that :)
|
(just checking to see what backporting will look like in terms of conflicts) |
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
- It is very "loose": it relies on `AssetLoader` to "attest" that it needs the seek feature. However, AssetLoaders both have access to the `AsyncSeek` API no matter what (it is a supertrait of Reader), and AssetReaders provide `AsyncSeek` behavior even if it isn't requested. In practice this is likely to create situations where AssetLoaders don't request `AsyncSeek` and just rely on it being provided by default, causing unexpected incompatibilities when AssetLoader consumers try to use other AssetReaders that don't support AsyncSeek. - It encourages building "fallback" behavior into the AssetReader in cases where AsyncSeek cannot be supported directly (ex: read the while contents into a Vec). From the perspective of loaders, this _silently_ changes the performance characteristics, and _forces_ a specific kind of fallback behavior. It would be better if the fallback behavior was in the hands of the AssetLoader. - Remove `ReaderRequiredFeatures` and associated functionality - Add a new `SeekableReader` trait, where `SeekableReader: Reader + AsyncSeek`. - Add a new `Reader::seekable(&mut self) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError>`, which can either fail or cast to `SeekableReader`, if that is supported. ```rust let seekable_reader = reader.seekable()?; seekable_reader.seek(SeekFrom::Start(10)).await?; ``` This gives `AssetLoader` implementers more clarity when it comes to `Reader` feature support, gives them more autonomy over fallback behavior, makes our APIs more static, and cuts down on the complexity of the system as a whole. --------- Co-authored-by: andriyDev <andriydzikh@gmail.com> Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
| /// An [`AsyncRead`] implementation capable of reading a [`Vec<u8>`]. | ||
| pub struct VecReader { | ||
| bytes: Vec<u8>, | ||
| /// The bytes being read. This is the full original list of bytes. |
There was a problem hiding this comment.
These docs suggest that bytes should be readonly, which makes me think it should have stayed private with an accessor function.
|
Noticed a couple of issues with this PR on the 0.18.0 branch. Firstly, compile error related to
Also noticed some release content that references
|
|
Followed up previous comment in #22430. |
`ReaderRequiredFeatures` was added by #22104 and removed by #22182, but [some references](#22182 (comment)) snuck into the 0.18 branch. This was causing a compile error if the `trace` feature was enabled, and some release content was misleading.

Objective
#22104 added
AsyncSeeksupport, but it has some downsides:AssetLoaderto "attest" that it needs the seek feature. However, AssetLoaders both have access to theAsyncSeekAPI no matter what (it is a supertrait of Reader), and AssetReaders provideAsyncSeekbehavior even if it isn't requested. In practice this is likely to create situations where AssetLoaders don't requestAsyncSeekand just rely on it being provided by default, causing unexpected incompatibilities when AssetLoader consumers try to use other AssetReaders that don't support AsyncSeek.Solution
ReaderRequiredFeaturesand associated functionalitySeekableReadertrait, whereSeekableReader: Reader + AsyncSeek.Reader::seekable(&mut self) -> Result<&mut dyn SeekableReader, ReaderNotSeekableError>, which can either fail or cast toSeekableReader, if that is supported.This gives
AssetLoaderimplementers more clarity when it comes toReaderfeature support, gives them more autonomy over fallback behavior, makes our APIs more static, and cuts down on the complexity of the system as a whole.