Skip to content

Commit

Permalink
clippy: single_match_else
Browse files Browse the repository at this point in the history
replace single match else with more idiomatic if let else

https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
  • Loading branch information
jqnatividad committed Aug 16, 2024
1 parent 21fdba9 commit 92cd2a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
15 changes: 6 additions & 9 deletions src/cmd/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,17 +1395,14 @@ fn beginend_insertrecord(
headers_count: usize,
wtr: &mut csv::Writer<Box<dyn Write>>,
) -> Result<(), CliError> {
match luau.globals().raw_get(QSV_INSERTRECORD_TBL) {
Ok(Value::Table(insertrecord_table)) => {
// QSV_INSERTRECORD_TBL is populated, we have a record to insert
insertrecord.clear();
if let Ok(Value::Table(insertrecord_table)) = luau.globals().raw_get(QSV_INSERTRECORD_TBL) {
// QSV_INSERTRECORD_TBL is populated, we have a record to insert
insertrecord.clear();

create_insertrecord(&insertrecord_table, insertrecord, headers_count)?;
create_insertrecord(&insertrecord_table, insertrecord, headers_count)?;

wtr.write_record(&*insertrecord)?;
insertrecord_table.clear()?;
},
Ok(_) | Err(_) => {},
wtr.write_record(&*insertrecord)?;
insertrecord_table.clear()?;
}
Ok(())
}
Expand Down
67 changes: 32 additions & 35 deletions src/cmd/snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,39 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
// this is automatically deleted when temp_download goes out of scope
let temp_download = NamedTempFile::new()?;

let input_reader: Box<dyn BufRead> = match &args.arg_input {
Some(uri) => {
let path = if Url::parse(uri).is_ok() && uri.starts_with("http") {
// its a remote file, download it first
let future = util::download_file(
uri,
temp_download.path().to_path_buf(),
args.flag_progressbar && !args.cmd_check && !args.flag_quiet,
args.flag_user_agent,
Some(args.flag_timeout),
if args.cmd_check {
Some(50) // only download 50 bytes when checking for a snappy header
} else {
None
},
);
tokio::runtime::Runtime::new()?.block_on(future)?;
// safety: temp_download is a NamedTempFile, so we know that it can be converted
let temp_download_path = temp_download.path().to_str().unwrap().to_string();
temp_download_path
} else {
// its a local file
uri.to_string()
};
let input_reader: Box<dyn BufRead> = if let Some(uri) = &args.arg_input {
let path = if Url::parse(uri).is_ok() && uri.starts_with("http") {
// its a remote file, download it first
let future = util::download_file(
uri,
temp_download.path().to_path_buf(),
args.flag_progressbar && !args.cmd_check && !args.flag_quiet,
args.flag_user_agent,
Some(args.flag_timeout),
if args.cmd_check {
Some(50) // only download 50 bytes when checking for a snappy header
} else {
None
},
);
tokio::runtime::Runtime::new()?.block_on(future)?;
// safety: temp_download is a NamedTempFile, so we know that it can be converted
let temp_download_path = temp_download.path().to_str().unwrap().to_string();
temp_download_path
} else {
// its a local file
uri.to_string()
};

let file = fs::File::open(path)?;
input_bytes = file.metadata()?.len();
Box::new(io::BufReader::with_capacity(
config::DEFAULT_RDR_BUFFER_CAPACITY,
file,
))
},
None => {
input_bytes = 0;
Box::new(io::BufReader::new(stdin().lock()))
},
let file = fs::File::open(path)?;
input_bytes = file.metadata()?.len();
Box::new(io::BufReader::with_capacity(
config::DEFAULT_RDR_BUFFER_CAPACITY,
file,
))
} else {
input_bytes = 0;
Box::new(io::BufReader::new(stdin().lock()))
};

let output_writer: Box<dyn Write + Send + 'static> = match &args.flag_output {
Expand Down

0 comments on commit 92cd2a0

Please sign in to comment.