Add more load_direct implementations
Objective
- Introduce variants of
LoadContext::load_directwhich allow picking asset type & configuring settings. - Fixes #12963.
Solution
- Implements
ErasedLoadedAsset::downcastand adds some accessors toLoadedAsset<A>. - Changes
load_direct/load_direct_with_readerto be typed, and introducesload_direct_untyped/load_direct_untyped_with_reader. - Introduces
load_direct_with_settingsandload_direct_with_reader_and_settings.
Testing
- I've run cargo test and played with the examples which use
load_direct. - I also extended the
asset_processingexample to use the new typed version ofload_directand useload_direct_with_settings.
Changelog
- Introduced new
load_directmethods inLoadContextto allow specifying type & settings
Migration Guide
-
LoadContext::load_directhas been renamed toLoadContext::load_direct_untyped. You may find the newload_directis more appropriate for your use case (and the migration may only be moving one type parameter). -
LoadContext::load_direct_with_readerhas been renamed toLoadContext::load_direct_untyped_with_reader.
This might not be an obvious win as a solution because it introduces quite a few new load_direct alternatives - but it does follow the existing pattern pretty well. I'm very open to alternatives. :sweat_smile:
@alice-i-cecile I've had a go at implementing a builder-style API. I suspect this is more open to bike-shedding (in particular .load_direct().load() isn't my favourite), and more likely to have other issues. However, I did the simpler tidy-up in the prior commits, in case this proves to be more controversial.
Hmm, I don't think that's an improvement 😅 Neat to see, but I would probably revert the builder experiment. I'll ask folks for more opinions / ideas.