@@ -289,6 +289,22 @@ impl AsRawHandle for RandomAccessFile {
289
289
}
290
290
}
291
291
292
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
293
+ impl AsFd for RandomAccessFile {
294
+ #[ inline]
295
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
296
+ self . 0 . as_fd ( )
297
+ }
298
+ }
299
+
300
+ #[ cfg( target_os = "windows" ) ]
301
+ impl AsHandle for RandomAccessFile {
302
+ #[ inline]
303
+ fn as_handle ( & self ) -> BorrowedHandle < ' _ > {
304
+ self . 0 . as_handle ( )
305
+ }
306
+ }
307
+
292
308
#[ cfg( any( unix, target_os = "wasi" ) ) ]
293
309
impl FromRawFd for RandomAccessFile {
294
310
#[ inline]
@@ -305,6 +321,22 @@ impl FromRawHandle for RandomAccessFile {
305
321
}
306
322
}
307
323
324
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
325
+ impl From < OwnedFd > for RandomAccessFile {
326
+ #[ inline]
327
+ fn from ( fd : OwnedFd ) -> Self {
328
+ Self :: from ( File :: from ( fd) )
329
+ }
330
+ }
331
+
332
+ #[ cfg( target_os = "windows" ) ]
333
+ impl From < OwnedHandle > for RandomAccessFile {
334
+ #[ inline]
335
+ fn from ( handle : OwnedHandle ) -> Self {
336
+ Self :: from ( File :: from ( handle) )
337
+ }
338
+ }
339
+
308
340
#[ cfg( any( unix, target_os = "wasi" ) ) ]
309
341
impl IntoRawFd for RandomAccessFile {
310
342
#[ inline]
@@ -321,6 +353,22 @@ impl IntoRawHandle for RandomAccessFile {
321
353
}
322
354
}
323
355
356
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
357
+ impl From < RandomAccessFile > for OwnedFd {
358
+ #[ inline]
359
+ fn from ( f : RandomAccessFile ) -> Self {
360
+ f. 0 . into ( )
361
+ }
362
+ }
363
+
364
+ #[ cfg( target_os = "windows" ) ]
365
+ impl From < RandomAccessFile > for OwnedHandle {
366
+ #[ inline]
367
+ fn from ( f : RandomAccessFile ) -> Self {
368
+ f. 0 . into ( )
369
+ }
370
+ }
371
+
324
372
/// A file wrapper that is safe to use concurrently.
325
373
///
326
374
/// This wrapper exists because [`std::fs::File`] uses a single cursor, so
@@ -488,6 +536,22 @@ impl AsRawHandle for SyncFile {
488
536
}
489
537
}
490
538
539
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
540
+ impl AsFd for SyncFile {
541
+ #[ inline]
542
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
543
+ self . 0 . get_ref ( ) . as_fd ( )
544
+ }
545
+ }
546
+
547
+ #[ cfg( target_os = "windows" ) ]
548
+ impl AsHandle for SyncFile {
549
+ #[ inline]
550
+ fn as_handle ( & self ) -> BorrowedHandle < ' _ > {
551
+ self . 0 . get_ref ( ) . as_handle ( )
552
+ }
553
+ }
554
+
491
555
#[ cfg( any( unix, target_os = "wasi" ) ) ]
492
556
impl FromRawFd for SyncFile {
493
557
#[ inline]
@@ -504,6 +568,22 @@ impl FromRawHandle for SyncFile {
504
568
}
505
569
}
506
570
571
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
572
+ impl From < OwnedFd > for SyncFile {
573
+ #[ inline]
574
+ fn from ( fd : OwnedFd ) -> Self {
575
+ Self :: from ( File :: from ( fd) )
576
+ }
577
+ }
578
+
579
+ #[ cfg( target_os = "windows" ) ]
580
+ impl From < OwnedHandle > for SyncFile {
581
+ #[ inline]
582
+ fn from ( handle : OwnedHandle ) -> Self {
583
+ Self :: from ( File :: from ( handle) )
584
+ }
585
+ }
586
+
507
587
impl fmt:: Debug for SyncFile {
508
588
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
509
589
f. debug_struct ( "SyncFile" )
0 commit comments