Skip to content

get_path_ref method for AssetServer #10685

Open

Description

What problem does this solve or what need does it fill?

While working with a folder handles, I needed to extract paths of all handles from inside the folder, and pass them into an external function to process. For performance reasons, I wanted to avoid unnecessary cloning of paths, and originally wrote the code expecting to pass around an iterator of &Path, but when I started implementing asset handles logic itself, I faced with an issue that AssetServer::get_path returns an owned instance of AssetPath, preventing me from getting &AssetServer-lifetime reference to asset paths, and forcing me to do cloning (for potentially thousands of files)

What solution would you like?

Some sort of method to get AssetPath by reference, instead of an owned instance.

Example impl:

    pub fn get_path_ref<'a>(&'a self, id: impl Into<UntypedAssetId>) -> Option<&'a AssetPath> {
        let infos = self.data.infos.read();
        let info = infos.get(id.into())?;
        info.path.as_ref()
    }

What alternative(s) have you considered?

Cloning Paths into PathBufs, which is fine on smaller scales, but still incurs a non-zero cost when working with large handles amounts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-AssetsLoad files from disk to use for things like images, models, and soundsLoad files from disk to use for things like images, models, and soundsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with BevyNice and easy! A great choice to get started with BevyS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions