@@ -22,10 +22,8 @@ pub mod cwdsource;
2222pub mod filesource;
2323mod homethunk;
2424pub mod terminalsource;
25- pub mod varsource;
2625
2726use cwdsource:: * ;
28- use varsource:: * ;
2927
3028/// An abstraction for the current process.
3129///
@@ -62,11 +60,11 @@ use varsource::*;
6260/// methods are in performance critical loops (except perhaps progress bars -
6361/// and even there we should be doing debouncing and managing update rates).
6462#[ enum_dispatch]
65- pub trait CurrentProcess : CurrentDirSource + VarSource + Debug { }
63+ pub trait CurrentProcess : CurrentDirSource + Debug { }
6664
6765/// Allows concrete types for the currentprocess abstraction.
6866#[ derive( Clone , Debug ) ]
69- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
67+ #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
7068pub enum Process {
7169 OSProcess ( OSProcess ) ,
7270 #[ cfg( feature = "test" ) ]
@@ -87,6 +85,25 @@ impl Process {
8785 . map ( String :: from)
8886 }
8987
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+
90107 pub ( crate ) fn args ( & self ) -> Box < dyn Iterator < Item = String > + ' _ > {
91108 match self {
92109 Process :: OSProcess ( _) => Box :: new ( env:: args ( ) ) ,
0 commit comments