@@ -16,6 +16,7 @@ use crate::fmt;
16
16
use crate :: io:: { self , BorrowedCursor , IoSlice , IoSliceMut , Read , Seek , SeekFrom , Write } ;
17
17
use crate :: path:: { Path , PathBuf } ;
18
18
use crate :: sealed:: Sealed ;
19
+ use crate :: sync:: Arc ;
19
20
use crate :: sys:: fs as fs_imp;
20
21
use crate :: sys_common:: { AsInner , AsInnerMut , FromInner , IntoInner } ;
21
22
use crate :: time:: SystemTime ;
@@ -743,7 +744,7 @@ fn buffer_capacity_required(mut file: &File) -> Option<usize> {
743
744
}
744
745
745
746
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
746
- impl Read for File {
747
+ impl Read for & File {
747
748
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
748
749
self . inner . read ( buf)
749
750
}
@@ -776,7 +777,7 @@ impl Read for File {
776
777
}
777
778
}
778
779
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
779
- impl Write for File {
780
+ impl Write for & File {
780
781
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
781
782
self . inner . write ( buf)
782
783
}
@@ -795,67 +796,99 @@ impl Write for File {
795
796
}
796
797
}
797
798
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
798
- impl Seek for File {
799
+ impl Seek for & File {
799
800
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
800
801
self . inner . seek ( pos)
801
802
}
802
803
}
804
+
803
805
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
804
- impl Read for & File {
806
+ impl Read for File {
805
807
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
806
- self . inner . read ( buf)
808
+ ( & * self ) . read ( buf)
809
+ }
810
+ fn read_vectored ( & mut self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
811
+ ( & * self ) . read_vectored ( bufs)
807
812
}
808
-
809
813
fn read_buf ( & mut self , cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
810
- self . inner . read_buf ( cursor)
814
+ ( & * self ) . read_buf ( cursor)
815
+ }
816
+ #[ inline]
817
+ fn is_read_vectored ( & self ) -> bool {
818
+ ( & & * self ) . is_read_vectored ( )
819
+ }
820
+ fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
821
+ ( & * self ) . read_to_end ( buf)
822
+ }
823
+ fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
824
+ ( & * self ) . read_to_string ( buf)
825
+ }
826
+ }
827
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
828
+ impl Write for File {
829
+ fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
830
+ ( & * self ) . write ( buf)
831
+ }
832
+ fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
833
+ ( & * self ) . write_vectored ( bufs)
834
+ }
835
+ #[ inline]
836
+ fn is_write_vectored ( & self ) -> bool {
837
+ ( & & * self ) . is_write_vectored ( )
838
+ }
839
+ fn flush ( & mut self ) -> io:: Result < ( ) > {
840
+ ( & * self ) . flush ( )
841
+ }
842
+ }
843
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
844
+ impl Seek for File {
845
+ fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
846
+ ( & * self ) . seek ( pos)
811
847
}
848
+ }
812
849
850
+ #[ stable( feature = "io_traits_arc" , since = "CURRENT_RUSTC_VERSION" ) ]
851
+ impl Read for Arc < File > {
852
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
853
+ ( & * * self ) . read ( buf)
854
+ }
813
855
fn read_vectored ( & mut self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
814
- self . inner . read_vectored ( bufs)
856
+ ( & * * self ) . read_vectored ( bufs)
857
+ }
858
+ fn read_buf ( & mut self , cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
859
+ ( & * * self ) . read_buf ( cursor)
815
860
}
816
-
817
861
#[ inline]
818
862
fn is_read_vectored ( & self ) -> bool {
819
- self . inner . is_read_vectored ( )
863
+ ( & * * self ) . is_read_vectored ( )
820
864
}
821
-
822
- // Reserves space in the buffer based on the file size when available.
823
865
fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
824
- let size = buffer_capacity_required ( self ) ;
825
- buf. reserve ( size. unwrap_or ( 0 ) ) ;
826
- io:: default_read_to_end ( self , buf, size)
866
+ ( & * * self ) . read_to_end ( buf)
827
867
}
828
-
829
- // Reserves space in the buffer based on the file size when available.
830
868
fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
831
- let size = buffer_capacity_required ( self ) ;
832
- buf. reserve ( size. unwrap_or ( 0 ) ) ;
833
- io:: default_read_to_string ( self , buf, size)
869
+ ( & * * self ) . read_to_string ( buf)
834
870
}
835
871
}
836
- #[ stable( feature = "rust1 " , since = "1.0.0 " ) ]
837
- impl Write for & File {
872
+ #[ stable( feature = "io_traits_arc " , since = "CURRENT_RUSTC_VERSION " ) ]
873
+ impl Write for Arc < File > {
838
874
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
839
- self . inner . write ( buf)
875
+ ( & * * self ) . write ( buf)
840
876
}
841
-
842
877
fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
843
- self . inner . write_vectored ( bufs)
878
+ ( & * * self ) . write_vectored ( bufs)
844
879
}
845
-
846
880
#[ inline]
847
881
fn is_write_vectored ( & self ) -> bool {
848
- self . inner . is_write_vectored ( )
882
+ ( & * * self ) . is_write_vectored ( )
849
883
}
850
-
851
884
fn flush ( & mut self ) -> io:: Result < ( ) > {
852
- self . inner . flush ( )
885
+ ( & * * self ) . flush ( )
853
886
}
854
887
}
855
- #[ stable( feature = "rust1 " , since = "1.0.0 " ) ]
856
- impl Seek for & File {
888
+ #[ stable( feature = "io_traits_arc " , since = "CURRENT_RUSTC_VERSION " ) ]
889
+ impl Seek for Arc < File > {
857
890
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
858
- self . inner . seek ( pos)
891
+ ( & * * self ) . seek ( pos)
859
892
}
860
893
}
861
894
0 commit comments