Skip to content

Commit

Permalink
Add From<String> for AssetPath<'a> (bevyengine#6337)
Browse files Browse the repository at this point in the history
# Objective
Fixes bevyengine#6291 

## Solution
Implement `From<String>` for `AssetPath<'a>`
  • Loading branch information
Ian-Yy authored and ItsDoot committed Feb 1, 2023
1 parent 0e8310c commit 500bc44
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_asset/src/path.rs
Expand Up @@ -187,3 +187,15 @@ impl<'a> From<PathBuf> for AssetPath<'a> {
}
}
}

impl<'a> From<String> for AssetPath<'a> {
fn from(asset_path: String) -> Self {
let mut parts = asset_path.splitn(2, '#');
let path = PathBuf::from(parts.next().expect("Path must be set."));
let label = parts.next().map(String::from);
AssetPath {
path: Cow::Owned(path),
label: label.map(Cow::Owned),
}
}
}

0 comments on commit 500bc44

Please sign in to comment.