forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomethunk.rs
More file actions
49 lines (44 loc) · 1.25 KB
/
Copy pathhomethunk.rs
File metadata and controls
49 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// Adapts currentprocess to the trait home::Env
use std::ffi::OsString;
use std::io;
use std::ops::Deref;
use std::path::PathBuf;
use home::env as home;
use super::CurrentDirSource;
use super::HomeProcess;
use super::OSProcess;
use super::TestProcess;
use super::VarSource;
impl home::Env for Box<dyn HomeProcess + 'static> {
fn home_dir(&self) -> Option<PathBuf> {
(**self).home_dir()
}
fn current_dir(&self) -> Result<PathBuf, io::Error> {
home::Env::current_dir(&(**self))
}
fn var_os(&self, key: &str) -> Option<OsString> {
home::Env::var_os(&(**self), key)
}
}
impl home::Env for TestProcess {
fn home_dir(&self) -> Option<PathBuf> {
self.var("HOME").ok().map(|v| v.into())
}
fn current_dir(&self) -> Result<PathBuf, io::Error> {
CurrentDirSource::current_dir(self.deref())
}
fn var_os(&self, key: &str) -> Option<OsString> {
VarSource::var_os(self.deref(), key)
}
}
impl home::Env for OSProcess {
fn home_dir(&self) -> Option<PathBuf> {
home::OS_ENV.home_dir()
}
fn current_dir(&self) -> Result<PathBuf, io::Error> {
home::OS_ENV.current_dir()
}
fn var_os(&self, key: &str) -> Option<OsString> {
home::OS_ENV.var_os(key)
}
}