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:
parent
b04451a1bd
commit
ef0628c48e
|
|
@ -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 -
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue