Root clippy fixes

This commit is contained in:
NGnius (Graham) 2022-01-29 16:13:52 -05:00
parent 9c2a20ef40
commit d908a0a033
2 changed files with 11 additions and 15 deletions

View file

@ -53,7 +53,7 @@ fn main() {
if let Some(script_file) = &args.file { if let Some(script_file) = &args.file {
// interpret script // interpret script
// script file checks // script file checks
if let Err(_) = file_checks(script_file) { if file_checks(script_file).is_err() {
return; return;
} }
// build playback controller // build playback controller
@ -61,18 +61,16 @@ fn main() {
let player_builder = move || { let player_builder = move || {
let script_reader = io::BufReader::new( let script_reader = io::BufReader::new(
std::fs::File::open(&script_file2) std::fs::File::open(&script_file2)
.expect(&format!("Abort: Cannot open file `{}`", &script_file2)), .unwrap_or_else(|_| panic!("Abort: Cannot open file `{}`", &script_file2)),
); );
let runner = MpsRunner::with_stream(script_reader); let runner = MpsRunner::with_stream(script_reader);
let player = MpsPlayer::new(runner).unwrap();
player MpsPlayer::new(runner).unwrap()
}; };
if let Some(playlist_file) = &args.playlist { if let Some(playlist_file) = &args.playlist {
// generate playlist // generate playlist
let mut player = player_builder(); let mut player = player_builder();
let mut writer = io::BufWriter::new(std::fs::File::create(playlist_file).expect( let mut writer = io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| panic!("Abort: Cannot create writeable file `{}`", playlist_file)));
&format!("Abort: Cannot create writeable file `{}`", playlist_file),
));
match player.save_m3u8(&mut writer) { match player.save_m3u8(&mut writer) {
Ok(_) => println!( Ok(_) => println!(
"Succes: Finished playlist `{}` from script `{}`", "Succes: Finished playlist `{}` from script `{}`",

View file

@ -37,16 +37,14 @@ pub fn repl(args: CliArgs) {
let (writer, reader) = channel_io(); let (writer, reader) = channel_io();
let player_builder = move || { let player_builder = move || {
let runner = MpsRunner::with_stream(reader); let runner = MpsRunner::with_stream(reader);
let player = MpsPlayer::new(runner).unwrap();
player MpsPlayer::new(runner).unwrap()
}; };
let mut state = ReplState::new(writer); let mut state = ReplState::new(writer);
if let Some(playlist_file) = &args.playlist { if let Some(playlist_file) = &args.playlist {
println!("Playlist mode (output: `{}`)", playlist_file); println!("Playlist mode (output: `{}`)", playlist_file);
let mut player = player_builder(); let mut player = player_builder();
let mut playlist_writer = io::BufWriter::new(std::fs::File::create(playlist_file).expect( let mut playlist_writer = io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| panic!("Abort: Cannot create writeable file `{}`", playlist_file)));
&format!("Abort: Cannot create writeable file `{}`", playlist_file),
));
read_loop(&args, &mut state, || { read_loop(&args, &mut state, || {
match player.save_m3u8(&mut playlist_writer) { match player.save_m3u8(&mut playlist_writer) {
Ok(_) => {} Ok(_) => {}
@ -126,12 +124,12 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
} }
'\n' => { '\n' => {
let statement_result = std::str::from_utf8(state.statement_buf.as_slice()); let statement_result = std::str::from_utf8(state.statement_buf.as_slice());
if statement_result.is_ok() && statement_result.unwrap().trim().starts_with("?") { if statement_result.is_ok() && statement_result.unwrap().trim().starts_with('?') {
//println!("Got {}", statement_result.unwrap()); //println!("Got {}", statement_result.unwrap());
repl_commands(statement_result.unwrap().trim()); repl_commands(statement_result.unwrap().trim());
state.statement_buf.clear(); state.statement_buf.clear();
} else if state.bracket_depth == 0 && state.in_literal.is_none() { } else if state.bracket_depth == 0 && state.in_literal.is_none() {
state.statement_buf.push(';' as u8); state.statement_buf.push(b';');
state state
.writer .writer
.write(state.statement_buf.as_slice()) .write(state.statement_buf.as_slice())
@ -159,7 +157,7 @@ fn error_prompt(error: mps_player::PlaybackError, args: &CliArgs) {
} }
fn repl_commands(command_str: &str) { fn repl_commands(command_str: &str) {
let words: Vec<&str> = command_str.split(" ").map(|s| s.trim()).collect(); let words: Vec<&str> = command_str.split(' ').map(|s| s.trim()).collect();
match words[0] { match words[0] {
"?help" => println!("{}", super::help::HELP_STRING), "?help" => println!("{}", super::help::HELP_STRING),
"?function" | "?functions" => println!("{}", super::help::FUNCTIONS), "?function" | "?functions" => println!("{}", super::help::FUNCTIONS),