From e218a24ca0f4f4ffe6a60b9cdb5a4f065014e870 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 5 Dec 2021 17:06:43 +0100 Subject: Shrink surface of StateDir path helper type Signed-off-by: Matthias Beyer --- src/profile.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/profile.rs') diff --git a/src/profile.rs b/src/profile.rs index 27af79c..cf74520 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -67,7 +67,7 @@ impl Profile { } async fn ipfs_path(state_dir: &StateDir, name: &str) -> Result { - let path = state_dir.path().join("ipfs"); + let path = state_dir.ipfs(); tokio::fs::create_dir_all(&path).await?; Ok(path) } @@ -140,8 +140,16 @@ impl Profile { pub struct StateDir(PathBuf); impl StateDir { - pub fn path(&self) -> &Path { - &self.0 + pub fn ipfs(&self) -> PathBuf { + self.0.join("ipfs") + } + + pub fn profile_state(&self) -> PathBuf { + self.0.join("profile_state") + } + + pub fn display(&self) -> std::path::Display { + self.0.display() } } @@ -193,7 +201,7 @@ impl ProfileStateSaveable { tokio::fs::OpenOptions::new() .create(true) .truncate(true) - .open(state_dir_path.path().join("profile_state")) + .open(&state_dir_path.profile_state()) .await? .write_all(state_s.as_bytes()) .await @@ -204,7 +212,7 @@ impl ProfileStateSaveable { pub async fn load_from_disk(state_dir_path: &StateDir) -> Result { let reader = tokio::fs::OpenOptions::new() .read(true) - .open(state_dir_path.path().join("profile_state")) + .open(&state_dir_path.profile_state()) .await? .into_std() .await; -- cgit v1.2.3