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

  1. use std::path::{self, PathBuf};
  2. use std::rc::Rc;
  3. #[derive(Clone, Debug)]
  4. pub struct Path(Rc<path::Path>);
  5. impl Path {
  6. pub(crate) fn clone_rc(&self) -> Rc<path::Path> {
  7. Rc::clone(&self.0)
  8. }
  9. pub fn join(&self, path: impl AsRef<path::Path>) -> Self {
  10. Self::from(self.0.join(path))
  11. }
  12. }
  13. // FIXME: This is a specialization since with Path: AsRef<path::Path>
  14. // it would overwrite impl<T> From <T> for T
  15. //impl<T: AsRef<path::Path>> From<T> for Path {
  16. // fn from(v: T) -> Self {
  17. // Self(v.as_ref().into())
  18. // }
  19. //}
  20. macro_rules! path_from {
  21. ( $t:ty ) => {
  22. impl From<$t> for Path {
  23. fn from(v: $t) -> Self {
  24. let path: &path::Path = v.as_ref();
  25. Self(path.into())
  26. }
  27. }
  28. };
  29. }
  30. path_from!(String);
  31. path_from!(&str);
  32. path_from!(PathBuf);
  33. impl From<Rc<path::Path>> for Path {
  34. fn from(v: Rc<path::Path>) -> Self {
  35. Self(v)
  36. }
  37. }
  38. impl AsRef<path::Path> for Path {
  39. fn as_ref(&self) -> &path::Path {
  40. &self.0
  41. }
  42. }
  43. impl From<Path> for Rc<path::Path> {
  44. fn from(v: Path) -> Self {
  45. v.0
  46. }
  47. }
  48. impl From<&Path> for Rc<path::Path> {
  49. fn from(v: &Path) -> Self {
  50. v.0.clone()
  51. }
  52. }
  53. #[derive(Clone, Debug)]
  54. pub struct UserName(pub Rc<str>);
  55. #[derive(Clone, Debug)]
  56. pub struct ServiceName(pub Rc<str>);
  57. #[derive(Clone, Debug)]
  58. pub struct DatabaseName(pub Rc<str>);