Add From<String> for AssetPath<'a> (#6337)

# Objective
Fixes #6291 

## Solution
Implement `From<String>` for `AssetPath<'a>`
This commit is contained in:
Yyee 2022-10-24 14:14:24 +00:00
parent 0f3f628c48
commit c226fee707

View File

@ -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),
}
}
}