@@ -23,10 +23,8 @@ pub mod cwdsource;
23
23
pub mod filesource;
24
24
mod homethunk;
25
25
pub mod terminalsource;
26
- pub mod varsource;
27
26
28
27
use cwdsource:: * ;
29
- use varsource:: * ;
30
28
31
29
/// An abstraction for the current process.
32
30
///
@@ -63,11 +61,11 @@ use varsource::*;
63
61
/// methods are in performance critical loops (except perhaps progress bars -
64
62
/// and even there we should be doing debouncing and managing update rates).
65
63
#[ enum_dispatch]
66
- pub trait CurrentProcess : CurrentDirSource + VarSource + Debug { }
64
+ pub trait CurrentProcess : CurrentDirSource + Debug { }
67
65
68
66
/// Allows concrete types for the currentprocess abstraction.
69
67
#[ derive( Clone , Debug ) ]
70
- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
68
+ #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
71
69
pub enum Process {
72
70
OSProcess ( OSProcess ) ,
73
71
#[ cfg( feature = "test" ) ]
@@ -88,6 +86,25 @@ impl Process {
88
86
. map ( String :: from)
89
87
}
90
88
89
+ pub fn var ( & self , key : & str ) -> Result < String , env:: VarError > {
90
+ match self {
91
+ Process :: OSProcess ( _) => env:: var ( key) ,
92
+ #[ cfg( feature = "test" ) ]
93
+ Process :: TestProcess ( p) => match p. vars . get ( key) {
94
+ Some ( val) => Ok ( val. to_owned ( ) ) ,
95
+ None => Err ( env:: VarError :: NotPresent ) ,
96
+ } ,
97
+ }
98
+ }
99
+
100
+ pub ( crate ) fn var_os ( & self , key : & str ) -> Option < OsString > {
101
+ match self {
102
+ Process :: OSProcess ( _) => env:: var_os ( key) ,
103
+ #[ cfg( feature = "test" ) ]
104
+ Process :: TestProcess ( p) => p. vars . get ( key) . map ( OsString :: from) ,
105
+ }
106
+ }
107
+
91
108
pub ( crate ) fn args ( & self ) -> Box < dyn Iterator < Item = String > + ' _ > {
92
109
match self {
93
110
Process :: OSProcess ( _) => Box :: new ( env:: args ( ) ) ,
0 commit comments