18
18
19
19
const TEMPFILE_ATTEMPTS : u32 = 100 ;
20
20
21
- use libc;
22
- use nix;
23
- use openat;
24
21
use rand:: Rng ;
25
22
use std:: ffi:: OsStr ;
26
23
use std:: fs:: File ;
@@ -140,7 +137,7 @@ pub trait OpenatDirExt {
140
137
141
138
/// Create a `FileWriter` which provides a `std::io::BufWriter` and then atomically creates
142
139
/// the file at the destination, renaming it over an existing one if necessary.
143
- fn new_file_writer < ' a > ( & ' a self , mode : libc:: mode_t ) -> io:: Result < FileWriter > ;
140
+ fn new_file_writer ( & self , mode : libc:: mode_t ) -> io:: Result < FileWriter > ;
144
141
145
142
/// Atomically create or replace the destination file, calling the provided
146
143
/// function to generate the contents. Note that the contents of the
@@ -220,7 +217,7 @@ impl OpenatDirExt for openat::Dir {
220
217
}
221
218
222
219
fn remove_file_optional < P : openat:: AsPath > ( & self , p : P ) -> io:: Result < bool > {
223
- Ok ( impl_remove_file_optional ( self , p) ? )
220
+ impl_remove_file_optional ( self , p)
224
221
}
225
222
226
223
fn remove_dir_optional < P : openat:: AsPath > ( & self , p : P ) -> io:: Result < bool > {
@@ -414,8 +411,8 @@ impl OpenatDirExt for openat::Dir {
414
411
Ok ( ( ) )
415
412
}
416
413
417
- fn new_file_writer < ' a > ( & ' a self , mode : libc:: mode_t ) -> io:: Result < FileWriter > {
418
- let ( tmpf, name) = if let Some ( tmpf) = self . new_unnamed_file ( mode) . ok ( ) {
414
+ fn new_file_writer ( & self , mode : libc:: mode_t ) -> io:: Result < FileWriter > {
415
+ let ( tmpf, name) = if let Ok ( tmpf) = self . new_unnamed_file ( mode) {
419
416
( tmpf, None )
420
417
} else {
421
418
// FIXME allow this to be configurable
@@ -498,7 +495,7 @@ pub(crate) fn tempfile_in(
498
495
match d. new_file ( tmpname. as_str ( ) , mode) {
499
496
Ok ( f) => return Ok ( ( f, tmpname) ) ,
500
497
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: AlreadyExists => continue ,
501
- Err ( e) => Err ( e) ? ,
498
+ Err ( e) => return Err ( e) ,
502
499
}
503
500
}
504
501
Err ( io:: Error :: new (
@@ -515,7 +512,7 @@ pub(crate) fn tempfile_in(
515
512
/// optimal case where all components exist above.
516
513
pub ( crate ) fn impl_ensure_dir_all ( d : & openat:: Dir , p : & Path , mode : libc:: mode_t ) -> io:: Result < ( ) > {
517
514
if let Some ( parent) = p. parent ( ) {
518
- if parent. as_os_str ( ) . len ( ) > 0 {
515
+ if ! parent. as_os_str ( ) . is_empty ( ) {
519
516
impl_ensure_dir_all ( d, parent, mode) ?;
520
517
}
521
518
}
@@ -781,7 +778,7 @@ impl FileExt for File {
781
778
fn pread_exact ( & self , buf : & mut [ u8 ] , start_pos : usize ) -> io:: Result < ( ) > {
782
779
use nix:: sys:: uio:: pread;
783
780
784
- if buf. len ( ) == 0 {
781
+ if buf. is_empty ( ) {
785
782
return Err ( io:: Error :: new (
786
783
io:: ErrorKind :: InvalidInput ,
787
784
"zero-sized buffer in input" ,
0 commit comments