@@ -64,11 +64,11 @@ use varsource::*;
64
64
/// methods are in performance critical loops (except perhaps progress bars -
65
65
/// and even there we should be doing debouncing and managing update rates).
66
66
#[ enum_dispatch]
67
- pub trait CurrentProcess : home:: Env + CurrentDirSource + VarSource + ProcessSource + Debug { }
67
+ pub trait CurrentProcess : home:: Env + CurrentDirSource + VarSource + Debug { }
68
68
69
69
/// Allows concrete types for the currentprocess abstraction.
70
70
#[ derive( Clone , Debug ) ]
71
- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource , ProcessSource ) ]
71
+ #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
72
72
pub enum Process {
73
73
OSProcess ( OSProcess ) ,
74
74
#[ cfg( feature = "test" ) ]
@@ -128,6 +128,15 @@ impl Process {
128
128
Process :: TestProcess ( p) => Box :: new ( filesource:: TestWriter ( p. stderr . clone ( ) ) ) ,
129
129
}
130
130
}
131
+
132
+ #[ cfg( test) ]
133
+ fn id ( & self ) -> u64 {
134
+ match self {
135
+ Process :: OSProcess ( _) => std:: process:: id ( ) as u64 ,
136
+ #[ cfg( feature = "test" ) ]
137
+ Process :: TestProcess ( p) => p. id ,
138
+ }
139
+ }
131
140
}
132
141
133
142
/// Obtain the current instance of CurrentProcess
@@ -247,16 +256,6 @@ thread_local! {
247
256
pub ( crate ) static PROCESS : RefCell <Option <Process >> = const { RefCell :: new( None ) } ;
248
257
}
249
258
250
- // PID related things
251
- #[ enum_dispatch]
252
- pub trait ProcessSource {
253
- /// Returns a unique id for the process.
254
- ///
255
- /// Real process ids are <= u32::MAX.
256
- /// Test process ids are > u32::MAX
257
- fn id ( & self ) -> u64 ;
258
- }
259
-
260
259
// ----------- real process -----------------
261
260
262
261
#[ derive( Clone , Debug ) ]
@@ -280,12 +279,6 @@ impl Default for OSProcess {
280
279
}
281
280
}
282
281
283
- impl ProcessSource for OSProcess {
284
- fn id ( & self ) -> u64 {
285
- std:: process:: id ( ) as u64
286
- }
287
- }
288
-
289
282
// ------------ test process ----------------
290
283
#[ cfg( feature = "test" ) ]
291
284
#[ derive( Clone , Debug , Default ) ]
@@ -342,21 +335,14 @@ impl TestProcess {
342
335
}
343
336
}
344
337
345
- #[ cfg( feature = "test" ) ]
346
- impl ProcessSource for TestProcess {
347
- fn id ( & self ) -> u64 {
348
- self . id
349
- }
350
- }
351
-
352
338
#[ cfg( test) ]
353
339
mod tests {
354
340
use std:: collections:: HashMap ;
355
341
use std:: env;
356
342
357
343
use rustup_macros:: unit_test as test;
358
344
359
- use super :: { process, with, ProcessSource , TestProcess } ;
345
+ use super :: { process, with, TestProcess } ;
360
346
361
347
#[ test]
362
348
fn test_instance ( ) {
@@ -367,7 +353,7 @@ mod tests {
367
353
"" ,
368
354
) ;
369
355
with ( proc. clone ( ) . into ( ) , || {
370
- assert_eq ! ( proc. id( ) , process( ) . id( ) , "{:?} != {:?}" , proc, process( ) )
356
+ assert_eq ! ( proc. id, process( ) . id( ) , "{:?} != {:?}" , proc, process( ) )
371
357
} ) ;
372
358
}
373
359
}
0 commit comments