File tree 1 file changed +4
-2
lines changed
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -260,7 +260,8 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
260
260
fn inner ( path : & Path ) -> io:: Result < Vec < u8 > > {
261
261
let mut file = File :: open ( path) ?;
262
262
let size = file. metadata ( ) . map ( |m| m. len ( ) as usize ) . ok ( ) ;
263
- let mut bytes = Vec :: with_capacity ( size. unwrap_or ( 0 ) ) ;
263
+ let mut bytes = Vec :: new ( ) ;
264
+ bytes. try_reserve ( size. unwrap_or ( 0 ) ) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
264
265
io:: default_read_to_end ( & mut file, & mut bytes, size) ?;
265
266
Ok ( bytes)
266
267
}
@@ -302,7 +303,8 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
302
303
fn inner ( path : & Path ) -> io:: Result < String > {
303
304
let mut file = File :: open ( path) ?;
304
305
let size = file. metadata ( ) . map ( |m| m. len ( ) as usize ) . ok ( ) ;
305
- let mut string = String :: with_capacity ( size. unwrap_or ( 0 ) ) ;
306
+ let mut string = String :: new ( ) ;
307
+ string. try_reserve ( size. unwrap_or ( 0 ) ) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
306
308
io:: default_read_to_string ( & mut file, & mut string, size) ?;
307
309
Ok ( string)
308
310
}
You can’t perform that action at this time.
0 commit comments