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 Pietrek14 committed Dec 17, 2022
1 parent 48ca0e9 commit 5b431ec
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
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 5b431ec

Please sign in to comment.