use std::path::{self, PathBuf}; use std::rc::Rc; #[derive(Clone, Debug)] pub struct Path(Rc); impl Path { pub(crate) fn clone_rc(&self) -> Rc { Rc::clone(&self.0) } pub fn join(&self, path: impl AsRef) -> Self { Self::from(self.0.join(path)) } } // FIXME: This is a specialization since with Path: AsRef // it would overwrite impl From for T //impl> From for Path { // fn from(v: T) -> Self { // Self(v.as_ref().into()) // } //} macro_rules! path_from { ( $t:ty ) => { impl From<$t> for Path { fn from(v: $t) -> Self { let path: &path::Path = v.as_ref(); Self(path.into()) } } }; } path_from!(String); path_from!(&str); path_from!(PathBuf); impl From> for Path { fn from(v: Rc) -> Self { Self(v) } } impl AsRef for Path { fn as_ref(&self) -> &path::Path { &self.0 } } impl From for Rc { fn from(v: Path) -> Self { v.0 } } impl From<&Path> for Rc { fn from(v: &Path) -> Self { v.0.clone() } } #[derive(Clone, Debug)] pub struct UserName(pub Rc); #[derive(Clone, Debug)] pub struct ServiceName(pub Rc); #[derive(Clone, Debug)] pub struct DatabaseName(pub Rc);