-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Allow Reader to implement AsyncSeek and provide a way for loaders to "ask" for a compatible reader.
#22104
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
base: main
Are you sure you want to change the base?
Conversation
f515166 to
8c5977d
Compare
… communicate what features they need from the read.
| @@ -1,3 +1,5 @@ | |||
| #[cfg(feature = "trace")] | |||
| use crate::io::ReaderRequiredFeatures; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could be in the #[cfg(feature = "trace")] use { block below
atlv24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job, looks good to me
| fn reader_required_features( | ||
| &self, | ||
| settings: &dyn Settings, | ||
| ) -> Result<ReaderRequiredFeatures, ProcessError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this have a default implementation? That would remove a bunch of boilerplate.
Objective
AsyncSeektrait byAsyncSeekForwardforReaderto address #12880 #14194, we replacedAsyncSeekwithAsyncSeekForward. This allowed us to support more kinds of sources, but the cost was that loaders were more limited in what they could do with the reader.AsyncSeekForwardmade it difficult to deal with this (or impossible in some cases).AsyncSeektrait bound onReadermay limit options to stream bytes #12880.Solution
AssetLoaderto say which "features" of a reader it needs.AssetReaderso it can decide how to handle it.AssetReaderError::UnsupportedFeature.This design is kind of "weak" - there's no guarantee that a loader that requests
AnySeekwill get a reader that actually implementsAsyncSeek. Or on the other side, there's no guarantee that a loader actually requests the features that it uses. However, in practice it's likely enough: errors are likely to guide users to the correct situation. In the future, we could perhaps have a "sieve reader", which blocks any features the loader didn't explicitly request. Perhaps this is a debug only feature, or something that can be toggled.Testing