Extend AssetPath
This commit is contained in:
parent
5ffc55b416
commit
7db1b64e17
2 changed files with 22 additions and 1 deletions
|
@ -8,3 +8,4 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.203", features = ["derive"] }
|
serde = { version = "1.0.203", features = ["derive"] }
|
||||||
|
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Display, path::Path, str::FromStr};
|
use std::{
|
||||||
|
fmt::Display,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, Default)]
|
||||||
pub struct AssetPath {
|
pub struct AssetPath {
|
||||||
|
@ -138,3 +143,18 @@ impl From<String> for AssetPath {
|
||||||
Self { prefix: None, path }
|
Self { prefix: None, path }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<PathBuf> for AssetPath {
|
||||||
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
|
fn try_from(value: PathBuf) -> anyhow::Result<Self> {
|
||||||
|
let mut me: Self = value
|
||||||
|
.to_str()
|
||||||
|
.ok_or(anyhow!("failed to convert PathBuf to &str"))?
|
||||||
|
.into();
|
||||||
|
|
||||||
|
me.assume_prefix_free();
|
||||||
|
|
||||||
|
Ok(me)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue