@@ -254,10 +254,13 @@ fn initial_buffer_size(file: &File) -> usize {
254
254
/// ```
255
255
#[ stable( feature = "fs_read_write_bytes" , since = "1.26.0" ) ]
256
256
pub fn read < P : AsRef < Path > > ( path : P ) -> io:: Result < Vec < u8 > > {
257
- let mut file = File :: open ( path) ?;
258
- let mut bytes = Vec :: with_capacity ( initial_buffer_size ( & file) ) ;
259
- file. read_to_end ( & mut bytes) ?;
260
- Ok ( bytes)
257
+ fn inner ( path : & Path ) -> io:: Result < Vec < u8 > > {
258
+ let mut file = File :: open ( path) ?;
259
+ let mut bytes = Vec :: with_capacity ( initial_buffer_size ( & file) ) ;
260
+ file. read_to_end ( & mut bytes) ?;
261
+ Ok ( bytes)
262
+ }
263
+ inner ( path. as_ref ( ) )
261
264
}
262
265
263
266
/// Read the entire contents of a file into a string.
@@ -296,10 +299,13 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
296
299
/// ```
297
300
#[ stable( feature = "fs_read_write" , since = "1.26.0" ) ]
298
301
pub fn read_to_string < P : AsRef < Path > > ( path : P ) -> io:: Result < String > {
299
- let mut file = File :: open ( path) ?;
300
- let mut string = String :: with_capacity ( initial_buffer_size ( & file) ) ;
301
- file. read_to_string ( & mut string) ?;
302
- Ok ( string)
302
+ fn inner ( path : & Path ) -> io:: Result < String > {
303
+ let mut file = File :: open ( path) ?;
304
+ let mut string = String :: with_capacity ( initial_buffer_size ( & file) ) ;
305
+ file. read_to_string ( & mut string) ?;
306
+ Ok ( string)
307
+ }
308
+ inner ( path. as_ref ( ) )
303
309
}
304
310
305
311
/// Write a slice as the entire contents of a file.
@@ -326,7 +332,10 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
326
332
/// ```
327
333
#[ stable( feature = "fs_read_write_bytes" , since = "1.26.0" ) ]
328
334
pub fn write < P : AsRef < Path > , C : AsRef < [ u8 ] > > ( path : P , contents : C ) -> io:: Result < ( ) > {
329
- File :: create ( path) ?. write_all ( contents. as_ref ( ) )
335
+ fn inner ( path : & Path , contents : & [ u8 ] ) -> io:: Result < ( ) > {
336
+ File :: create ( path) ?. write_all ( contents)
337
+ }
338
+ inner ( path. as_ref ( ) , contents. as_ref ( ) )
330
339
}
331
340
332
341
impl File {
0 commit comments