Skip to content

Commit 53b31bc

Browse files
committed
Update code to use home::env as home as suggested
1 parent 1b7e263 commit 53b31bc

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/currentprocess.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
99
use std::sync::Once;
1010
use std::sync::{Arc, Mutex};
1111

12+
use home::env as home;
1213
use rand::{thread_rng, Rng};
1314

1415
pub(crate) mod argsource;
@@ -55,15 +56,15 @@ use varsource::*;
5556
/// The real trait is CurrentProcess; HomeProcess is a single trait because
5657
/// Box<T> only allows autotraits to be added to it; so we use a subtrait to add
5758
/// home::Env in.
58-
pub trait HomeProcess: CurrentProcess + home::env::Env {
59+
pub trait HomeProcess: CurrentProcess + home::Env {
5960
fn clone_boxed(&self) -> Box<dyn HomeProcess>;
6061
}
6162

6263
// Machinery for Cloning boxes
6364

6465
impl<T> HomeProcess for T
6566
where
66-
T: 'static + CurrentProcess + home::env::Env + Clone,
67+
T: 'static + CurrentProcess + home::Env + Clone,
6768
{
6869
fn clone_boxed(&self) -> Box<dyn HomeProcess + 'static> {
6970
Box::new(T::clone(self))

src/currentprocess/homethunk.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ use std::io;
44
use std::ops::Deref;
55
use std::path::PathBuf;
66

7+
use home::env as home;
8+
79
use super::CurrentDirSource;
810
use super::HomeProcess;
911
use super::OSProcess;
1012
use super::TestProcess;
1113
use super::VarSource;
1214

13-
impl home::env::Env for Box<dyn HomeProcess + 'static> {
15+
impl home::Env for Box<dyn HomeProcess + 'static> {
1416
fn home_dir(&self) -> Option<PathBuf> {
1517
(**self).home_dir()
1618
}
1719
fn current_dir(&self) -> Result<PathBuf, io::Error> {
18-
home::env::Env::current_dir(&(**self))
20+
home::Env::current_dir(&(**self))
1921
}
2022
fn var_os(&self, key: &str) -> Option<OsString> {
21-
home::env::Env::var_os(&(**self), key)
23+
home::Env::var_os(&(**self), key)
2224
}
2325
}
2426

25-
impl home::env::Env for TestProcess {
27+
impl home::Env for TestProcess {
2628
fn home_dir(&self) -> Option<PathBuf> {
2729
self.var("HOME").ok().map(|v| v.into())
2830
}
@@ -34,14 +36,14 @@ impl home::env::Env for TestProcess {
3436
}
3537
}
3638

37-
impl home::env::Env for OSProcess {
39+
impl home::Env for OSProcess {
3840
fn home_dir(&self) -> Option<PathBuf> {
39-
home::env::OS_ENV.home_dir()
41+
home::OS_ENV.home_dir()
4042
}
4143
fn current_dir(&self) -> Result<PathBuf, io::Error> {
42-
home::env::OS_ENV.current_dir()
44+
home::OS_ENV.current_dir()
4345
}
4446
fn var_os(&self, key: &str) -> Option<OsString> {
45-
home::env::OS_ENV.var_os(key)
47+
home::OS_ENV.var_os(key)
4648
}
4749
}

src/utils/utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::{self, BufReader, Write};
55
use std::path::{Path, PathBuf};
66

77
use anyhow::{anyhow, bail, Context, Result};
8+
use home::env as home;
89
use retry::delay::{jitter, Fibonacci};
910
use retry::{retry, OperationResult};
1011
use sha2::Sha256;
@@ -493,11 +494,11 @@ pub(crate) fn to_absolute<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
493494
}
494495

495496
pub(crate) fn home_dir() -> Option<PathBuf> {
496-
home::env::home_dir_with_env(&home_process())
497+
home::home_dir_with_env(&home_process())
497498
}
498499

499500
pub(crate) fn cargo_home() -> Result<PathBuf> {
500-
home::env::cargo_home_with_env(&home_process()).context("failed to determine cargo home")
501+
home::cargo_home_with_env(&home_process()).context("failed to determine cargo home")
501502
}
502503

503504
// Creates a ~/.rustup folder
@@ -524,7 +525,7 @@ fn rustup_home_in_user_dir() -> Result<PathBuf> {
524525
}
525526

526527
pub(crate) fn rustup_home() -> Result<PathBuf> {
527-
home::env::rustup_home_with_env(&home_process()).context("failed to determine rustup home dir")
528+
home::rustup_home_with_env(&home_process()).context("failed to determine rustup home dir")
528529
}
529530

530531
pub(crate) fn format_path_for_display(path: &str) -> String {

0 commit comments

Comments
 (0)