diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-05 17:06:43 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-06 16:29:01 +0100 |
commit | e218a24ca0f4f4ffe6a60b9cdb5a4f065014e870 (patch) | |
tree | d3238ac4ba971b1a5ac5de34319b8b8ed7c4421c /src | |
parent | 8a87137b15cf29362a5a2dd4c69aa34c74e63ee9 (diff) |
Shrink surface of StateDir path helper type
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/profile.rs | 2 | ||||
-rw-r--r-- | src/profile.rs | 18 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/commands/profile.rs b/src/commands/profile.rs index dbb55bf..98fbc08 100644 --- a/src/commands/profile.rs +++ b/src/commands/profile.rs @@ -14,7 +14,7 @@ pub async fn profile(matches: &ArgMatches) -> Result<()> { async fn profile_create(matches: &ArgMatches) -> Result<()> { let name = matches.value_of("name").map(String::from).unwrap(); // required let state_dir = Profile::state_dir_path(&name)?; - log::info!("Creating '{}' in {}", name, state_dir.path().display()); + log::info!("Creating '{}' in {}", name, state_dir.display()); let profile = Profile::create(&state_dir, &name, Config::default()).await?; log::info!("Saving..."); 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<PathBuf> { - 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<Self> { 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; |