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