Exchange From for TryFrom for PathBuf and Home

The `From` implementation would allow someone to create a `Home` in an
incorrect fashion, for example the path is not canonical.

Exchange `From` for a `TryFrom` implementation.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-02-16 15:40:32 +00:00 committed by Alexis Sellier
parent b04451a1bd
commit ef0628c48e
No known key found for this signature in database
3 changed files with 9 additions and 5 deletions

View File

@ -56,7 +56,7 @@ $ rad patch
- YOU PROPOSED -
define power requirements d4ef85f57a8 R0 3e674d1 (flux-capacitor-power) ahead 1, behind 0
└─ * opened by z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (you) [..]
└─ * opened by did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (you) [..]
└─ * patch id d4ef85f57a849bd845915d7a66a2192cd23811f6
- OTHERS PROPOSED -

View File

@ -1,3 +1,4 @@
use std::convert::TryInto as _;
use std::path::Path;
use std::str::FromStr;
use std::sync::Arc;
@ -81,7 +82,8 @@ pub fn seed(dir: &Path) -> Context {
.unwrap();
// eq. rad auth
let profile = radicle::Profile::init(rad_home.into(), PASSWORD.to_owned()).unwrap();
let profile =
radicle::Profile::init(rad_home.try_into().unwrap(), PASSWORD.to_owned()).unwrap();
// rad init
rad_init::init(

View File

@ -163,9 +163,11 @@ pub struct Home {
path: PathBuf,
}
impl From<PathBuf> for Home {
fn from(path: PathBuf) -> Self {
Self { path }
impl TryFrom<PathBuf> for Home {
type Error = io::Error;
fn try_from(home: PathBuf) -> Result<Self, Self::Error> {
Self::new(home)
}
}