bevyengine / bevyengine/bevy

`get_path_ref` method for AssetServer

Open
#10,685 4 comments 1 reaction 1 assignee Claimed by @PurityLake View on GitHub
A-Assets C-Usability D-Trivial S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

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:
```rs
pub fn get_path_ref<'a>(&'a self, id: impl Into) -> 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 `Path`s into `PathBuf`s, which is fine on smaller scales, but still incurs a non-zero cost when working with large handles amounts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.