@@ -65,11 +65,11 @@ use crate::utils::tty::{stderr_isatty, stdout_isatty};
65
65
/// methods are in performance critical loops (except perhaps progress bars -
66
66
/// and even there we should be doing debouncing and managing update rates).
67
67
#[ enum_dispatch]
68
- pub trait CurrentProcess : home:: Env + CurrentDirSource + VarSource + ProcessSource + Debug { }
68
+ pub trait CurrentProcess : home:: Env + CurrentDirSource + VarSource + Debug { }
69
69
70
70
/// Allows concrete types for the currentprocess abstraction.
71
71
#[ derive( Clone , Debug ) ]
72
- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource , ProcessSource ) ]
72
+ #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
73
73
pub enum Process {
74
74
OSProcess ( OSProcess ) ,
75
75
#[ cfg( feature = "test" ) ]
@@ -129,6 +129,15 @@ impl Process {
129
129
Process :: TestProcess ( p) => Box :: new ( filesource:: TestWriter ( p. stderr . clone ( ) ) ) ,
130
130
}
131
131
}
132
+
133
+ #[ cfg( test) ]
134
+ fn id ( & self ) -> u64 {
135
+ match self {
136
+ Process :: OSProcess ( _) => std:: process:: id ( ) as u64 ,
137
+ #[ cfg( feature = "test" ) ]
138
+ Process :: TestProcess ( p) => p. id ,
139
+ }
140
+ }
132
141
}
133
142
134
143
/// Obtain the current instance of CurrentProcess
@@ -182,16 +191,6 @@ thread_local! {
182
191
pub ( crate ) static PROCESS : RefCell <Option <Process >> = const { RefCell :: new( None ) } ;
183
192
}
184
193
185
- // PID related things
186
- #[ enum_dispatch]
187
- pub trait ProcessSource {
188
- /// Returns a unique id for the process.
189
- ///
190
- /// Real process ids are <= u32::MAX.
191
- /// Test process ids are > u32::MAX
192
- fn id ( & self ) -> u64 ;
193
- }
194
-
195
194
// ----------- real process -----------------
196
195
197
196
#[ derive( Clone , Debug ) ]
@@ -215,12 +214,6 @@ impl Default for OSProcess {
215
214
}
216
215
}
217
216
218
- impl ProcessSource for OSProcess {
219
- fn id ( & self ) -> u64 {
220
- std:: process:: id ( ) as u64
221
- }
222
- }
223
-
224
217
// ------------ test process ----------------
225
218
#[ cfg( feature = "test" ) ]
226
219
#[ derive( Clone , Debug , Default ) ]
@@ -276,21 +269,14 @@ impl TestProcess {
276
269
}
277
270
}
278
271
279
- #[ cfg( feature = "test" ) ]
280
- impl ProcessSource for TestProcess {
281
- fn id ( & self ) -> u64 {
282
- self . id
283
- }
284
- }
285
-
286
272
#[ cfg( test) ]
287
273
mod tests {
288
274
use std:: collections:: HashMap ;
289
275
use std:: env;
290
276
291
277
use rustup_macros:: unit_test as test;
292
278
293
- use super :: { process, with, ProcessSource , TestProcess } ;
279
+ use super :: { process, with, TestProcess } ;
294
280
295
281
#[ test]
296
282
fn test_instance ( ) {
@@ -301,7 +287,7 @@ mod tests {
301
287
"" ,
302
288
) ;
303
289
with ( proc. clone ( ) . into ( ) , || {
304
- assert_eq ! ( proc. id( ) , process( ) . id( ) , "{:?} != {:?}" , proc, process( ) )
290
+ assert_eq ! ( proc. id, process( ) . id( ) , "{:?} != {:?}" , proc, process( ) )
305
291
} ) ;
306
292
}
307
293
}
0 commit comments