From 357fc79b41b6381266f81ab7e508bf4e85419816 Mon Sep 17 00:00:00 2001 From: xphoniex Date: Sat, 5 Nov 2022 05:27:24 +0000 Subject: [PATCH] Implement `paths` for `Profile` Signed-off-by: xphoniex --- radicle/src/profile.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index b151557c..b54d9a68 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -11,7 +11,7 @@ //! radicle.sock # Node control socket //! use std::io; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use thiserror::Error; @@ -122,6 +122,11 @@ impl Profile { .map(PathBuf::from) .unwrap_or_else(|| self.home.join("node").join(node::DEFAULT_SOCKET_NAME)) } + + /// Get `Paths` of profile + pub fn paths(&self) -> Paths { + Paths { home: &self.home } + } } /// Get the path to the radicle home folder. @@ -137,3 +142,22 @@ pub fn home() -> Result { )) } } + +#[derive(Debug, Clone)] +pub struct Paths<'a> { + home: &'a Path, +} + +impl Paths<'_> { + pub fn storage(&self) -> PathBuf { + self.home.join("storage") + } + + pub fn keys(&self) -> PathBuf { + self.home.join("keys") + } + + pub fn node(&self) -> PathBuf { + self.home.join("node") + } +}