Hide Path implementation

This commit is contained in:
Adrian Heine 2020-08-03 19:28:05 +02:00
parent 10edcd4282
commit 7f5daa3c0e
4 changed files with 113 additions and 72 deletions

View file

@ -1,7 +1,36 @@
use std::path::{Path as ActualPath, PathBuf};
#[derive(Clone, Debug)]
pub struct Path(pub PathBuf);
pub struct Path(PathBuf);
// FIXME: This is a specialization since with Path: Into<PathBuf>
// it would overwrite impl<T> From <T> for T
//impl<T: Into<PathBuf>> From<T> for Path {
// fn from(v: T) -> Self {
// Path(v.into())
// }
//}
macro_rules! path_from {
( $t:ty ) => {
impl From<$t> for Path {
fn from(v: $t) -> Self {
Self(v.into())
}
}
};
}
path_from!(String);
path_from!(&str);
path_from!(PathBuf);
impl From<Path> for PathBuf {
fn from(v: Path) -> Self {
v.0
}
}
impl AsRef<ActualPath> for Path {
fn as_ref(&self) -> &ActualPath {
&self.0