A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.3 KiB

use std::path::{self, PathBuf};
use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct Path(Rc<path::Path>);
impl Path {
pub(crate) fn clone_rc(&self) -> Rc<path::Path> {
Rc::clone(&self.0)
}
pub fn join(&self, path: impl AsRef<path::Path>) -> Self {
Self::from(self.0.join(path))
}
}
// FIXME: This is a specialization since with Path: AsRef<path::Path>
// it would overwrite impl<T> From <T> for T
//impl<T: AsRef<path::Path>> From<T> 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<Rc<path::Path>> for Path {
fn from(v: Rc<path::Path>) -> Self {
Self(v)
}
}
impl AsRef<path::Path> for Path {
fn as_ref(&self) -> &path::Path {
&self.0
}
}
impl From<Path> for Rc<path::Path> {
fn from(v: Path) -> Self {
v.0
}
}
impl From<&Path> for Rc<path::Path> {
fn from(v: &Path) -> Self {
v.0.clone()
}
}
#[derive(Clone, Debug)]
pub struct UserName(pub Rc<str>);
#[derive(Clone, Debug)]
pub struct ServiceName(pub Rc<str>);
#[derive(Clone, Debug)]
pub struct DatabaseName(pub Rc<str>);