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