@@ -192,10 +192,6 @@ impl FileDescription for NullOutput {
192
192
pub struct FileDescriptor ( Rc < RefCell < Box < dyn FileDescription > > > ) ;
193
193
194
194
impl FileDescriptor {
195
- pub fn new < T : FileDescription > ( fd : T ) -> Self {
196
- FileDescriptor ( Rc :: new ( RefCell :: new ( Box :: new ( fd) ) ) )
197
- }
198
-
199
195
pub fn borrow ( & self ) -> Ref < ' _ , dyn FileDescription > {
200
196
Ref :: map ( self . 0 . borrow ( ) , |fd| fd. as_ref ( ) )
201
197
}
@@ -227,20 +223,25 @@ impl VisitProvenance for FdTable {
227
223
}
228
224
229
225
impl FdTable {
230
- pub ( crate ) fn new ( mute_stdout_stderr : bool ) -> FdTable {
231
- let mut fds: BTreeMap < _ , FileDescriptor > = BTreeMap :: new ( ) ;
232
- fds. insert ( 0i32 , FileDescriptor :: new ( io:: stdin ( ) ) ) ;
226
+ fn new ( ) -> Self {
227
+ FdTable { fds : BTreeMap :: new ( ) }
228
+ }
229
+ pub ( crate ) fn init ( mute_stdout_stderr : bool ) -> FdTable {
230
+ let mut fds = FdTable :: new ( ) ;
231
+ fds. insert_fd ( io:: stdin ( ) ) ;
233
232
if mute_stdout_stderr {
234
- fds. insert ( 1i32 , FileDescriptor :: new ( NullOutput ) ) ;
235
- fds. insert ( 2i32 , FileDescriptor :: new ( NullOutput ) ) ;
233
+ assert_eq ! ( fds. insert_fd ( NullOutput ) , 1 ) ;
234
+ assert_eq ! ( fds. insert_fd ( NullOutput ) , 2 ) ;
236
235
} else {
237
- fds. insert ( 1i32 , FileDescriptor :: new ( io:: stdout ( ) ) ) ;
238
- fds. insert ( 2i32 , FileDescriptor :: new ( io:: stderr ( ) ) ) ;
236
+ assert_eq ! ( fds. insert_fd ( io:: stdout( ) ) , 1 ) ;
237
+ assert_eq ! ( fds. insert_fd ( io:: stderr( ) ) , 2 ) ;
239
238
}
240
- FdTable { fds }
239
+ fds
241
240
}
242
241
243
- pub fn insert_fd ( & mut self , file_handle : FileDescriptor ) -> i32 {
242
+ /// Insert a file descriptor to the FdTable.
243
+ pub fn insert_fd < T : FileDescription > ( & mut self , fd : T ) -> i32 {
244
+ let file_handle = FileDescriptor ( Rc :: new ( RefCell :: new ( Box :: new ( fd) ) ) ) ;
244
245
self . insert_fd_with_min_fd ( file_handle, 0 )
245
246
}
246
247
0 commit comments