From 500bc44c50016b3fd99034b82a38a95f615e8f8c Mon Sep 17 00:00:00 2001 From: Yyee Date: Mon, 24 Oct 2022 14:14:24 +0000 Subject: [PATCH] Add From for AssetPath<'a> (#6337) # Objective Fixes #6291 ## Solution Implement `From` for `AssetPath<'a>` --- crates/bevy_asset/src/path.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 8cec8282e2e58..e9150c63a8834 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -187,3 +187,15 @@ impl<'a> From for AssetPath<'a> { } } } + +impl<'a> From 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), + } + } +}