@@ -16,6 +16,7 @@ use crate::fmt;
1616use crate :: io:: { self , BorrowedCursor , IoSlice , IoSliceMut , Read , Seek , SeekFrom , Write } ;
1717use crate :: path:: { Path , PathBuf } ;
1818use crate :: sealed:: Sealed ;
19+ use crate :: sync:: Arc ;
1920use crate :: sys:: fs as fs_imp;
2021use crate :: sys_common:: { AsInner , AsInnerMut , FromInner , IntoInner } ;
2122use crate :: time:: SystemTime ;
@@ -743,7 +744,7 @@ fn buffer_capacity_required(mut file: &File) -> Option<usize> {
743744}
744745
745746#[ stable( feature = "rust1" , since = "1.0.0" ) ]
746- impl Read for File {
747+ impl Read for & File {
747748 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
748749 self . inner . read ( buf)
749750 }
@@ -776,7 +777,7 @@ impl Read for File {
776777 }
777778}
778779#[ stable( feature = "rust1" , since = "1.0.0" ) ]
779- impl Write for File {
780+ impl Write for & File {
780781 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
781782 self . inner . write ( buf)
782783 }
@@ -795,67 +796,99 @@ impl Write for File {
795796 }
796797}
797798#[ stable( feature = "rust1" , since = "1.0.0" ) ]
798- impl Seek for File {
799+ impl Seek for & File {
799800 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
800801 self . inner . seek ( pos)
801802 }
802803}
804+
803805#[ stable( feature = "rust1" , since = "1.0.0" ) ]
804- impl Read for & File {
806+ impl Read for File {
805807 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)
807812 }
808-
809813 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)
811847 }
848+ }
812849
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+ }
813855 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)
815860 }
816-
817861 #[ inline]
818862 fn is_read_vectored ( & self ) -> bool {
819- self . inner . is_read_vectored ( )
863+ ( & * * self ) . is_read_vectored ( )
820864 }
821-
822- // Reserves space in the buffer based on the file size when available.
823865 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)
827867 }
828-
829- // Reserves space in the buffer based on the file size when available.
830868 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)
834870 }
835871}
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 > {
838874 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
839- self . inner . write ( buf)
875+ ( & * * self ) . write ( buf)
840876 }
841-
842877 fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
843- self . inner . write_vectored ( bufs)
878+ ( & * * self ) . write_vectored ( bufs)
844879 }
845-
846880 #[ inline]
847881 fn is_write_vectored ( & self ) -> bool {
848- self . inner . is_write_vectored ( )
882+ ( & * * self ) . is_write_vectored ( )
849883 }
850-
851884 fn flush ( & mut self ) -> io:: Result < ( ) > {
852- self . inner . flush ( )
885+ ( & * * self ) . flush ( )
853886 }
854887}
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 > {
857890 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
858- self . inner . seek ( pos)
891+ ( & * * self ) . seek ( pos)
859892 }
860893}
861894
0 commit comments