From 46459c7da10b28195f1cbf29a3f94133bae5b09c Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 31 Jan 2022 09:22:36 -0500 Subject: [PATCH] cargo fmt --- mps-interpreter/src/interpretor.rs | 7 ++- mps-interpreter/src/lang/filter.rs | 17 ++++--- mps-interpreter/src/lang/filter_replace.rs | 15 +++--- mps-interpreter/src/lang/function.rs | 2 +- mps-interpreter/src/lang/pseudo_op.rs | 5 +- mps-interpreter/src/lang/sorter.rs | 5 +- mps-interpreter/src/lang/vocabulary/empty.rs | 12 ++--- mps-interpreter/src/lang/vocabulary/files.rs | 5 +- mps-interpreter/src/lang/vocabulary/repeat.rs | 5 +- mps-interpreter/src/lang/vocabulary/reset.rs | 6 +-- .../vocabulary/sorters/bliss_next_sorter.rs | 47 ++++++++++++------- .../lang/vocabulary/sorters/bliss_sorter.rs | 4 +- .../src/lang/vocabulary/sorters/mod.rs | 10 ++-- .../src/lang/vocabulary/sorters/shuffle.rs | 14 +++--- mps-interpreter/src/music/tag.rs | 15 ++++-- mps-interpreter/src/processing/filesystem.rs | 16 ++++--- mps-interpreter/src/processing/sql.rs | 3 +- mps-interpreter/tests/single_line.rs | 18 ++----- mps-m3u8/src/cli.rs | 2 +- mps-m3u8/src/main.rs | 15 +++--- mps-player/src/os_controls.rs | 10 +++- mps-player/src/player.rs | 2 +- mps-player/src/player_wrapper.rs | 2 +- src/main.rs | 7 ++- src/repl.rs | 7 ++- 25 files changed, 142 insertions(+), 109 deletions(-) diff --git a/mps-interpreter/src/interpretor.rs b/mps-interpreter/src/interpretor.rs index ae3eaf7..f8307dd 100644 --- a/mps-interpreter/src/interpretor.rs +++ b/mps-interpreter/src/interpretor.rs @@ -90,7 +90,8 @@ where if next_item.is_none() { is_stmt_done = true; } - next_item.map(|item| item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()))) + next_item + .map(|item| item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()))) } else { /*if self.tokenizer.end_of_file() { return None; @@ -121,7 +122,9 @@ where if next_item.is_none() { is_stmt_done = true; } - next_item.map(|item| item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()))) + next_item.map(|item| { + item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line())) + }) } Err(e) => { Some(Err(e).map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()))) diff --git a/mps-interpreter/src/lang/filter.rs b/mps-interpreter/src/lang/filter.rs index 16b1e41..c5023dc 100644 --- a/mps-interpreter/src/lang/filter.rs +++ b/mps-interpreter/src/lang/filter.rs @@ -366,14 +366,17 @@ impl Iterator for MpsFilterStatement

{ fn size_hint(&self) -> (usize, Option) { match &self.iterable { - VariableOrOp::Variable(s) => self.context.as_ref() + VariableOrOp::Variable(s) => self + .context + .as_ref() .and_then(|x| x.variables.get_opt(s)) .and_then(|x| match x { - MpsType::Op(op) => Some(op.size_hint()), - _ => None - }), - VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok() - }.unwrap_or((0, None)) + MpsType::Op(op) => Some(op.size_hint()), + _ => None, + }), + VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok(), + } + .unwrap_or((0, None)) } } @@ -555,7 +558,7 @@ fn last_open_bracket_is_after_dot(tokens: &VecDeque) -> bool { inside_brackets -= 1; } } else if open_bracket_found { - return tokens[i].is_dot() + return tokens[i].is_dot(); } } false diff --git a/mps-interpreter/src/lang/filter_replace.rs b/mps-interpreter/src/lang/filter_replace.rs index 18d6a8f..e6bf36b 100644 --- a/mps-interpreter/src/lang/filter_replace.rs +++ b/mps-interpreter/src/lang/filter_replace.rs @@ -313,14 +313,17 @@ impl Iterator for MpsFilterReplaceStatement

fn size_hint(&self) -> (usize, Option) { match &self.iterable { - VariableOrOp::Variable(s) => self.context.as_ref() + VariableOrOp::Variable(s) => self + .context + .as_ref() .and_then(|x| x.variables.get_opt(s)) .and_then(|x| match x { - MpsType::Op(op) => Some(op.size_hint()), - _ => None - }), - VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok() - }.unwrap_or((0, None)) + MpsType::Op(op) => Some(op.size_hint()), + _ => None, + }), + VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok(), + } + .unwrap_or((0, None)) } } diff --git a/mps-interpreter/src/lang/function.rs b/mps-interpreter/src/lang/function.rs index 9d18515..0a1bceb 100644 --- a/mps-interpreter/src/lang/function.rs +++ b/mps-interpreter/src/lang/function.rs @@ -2,9 +2,9 @@ use std::collections::VecDeque; //use std::fmt::{Debug, Display, Error, Formatter}; use std::marker::PhantomData; -use crate::lang::utility::{assert_token, assert_token_raw, assert_token_raw_back}; #[cfg(debug_assertions)] use crate::lang::utility::assert_empty; +use crate::lang::utility::{assert_token, assert_token_raw, assert_token_raw_back}; use crate::lang::MpsLanguageDictionary; use crate::lang::SyntaxError; use crate::lang::{BoxedMpsOpFactory, MpsOp}; diff --git a/mps-interpreter/src/lang/pseudo_op.rs b/mps-interpreter/src/lang/pseudo_op.rs index b8e160b..c1ddffd 100644 --- a/mps-interpreter/src/lang/pseudo_op.rs +++ b/mps-interpreter/src/lang/pseudo_op.rs @@ -35,10 +35,7 @@ impl PseudoOp { pub fn unwrap_real(self) -> Result, RuntimeError> { match self { - Self::Real(op) => { - - Ok(op) - } + Self::Real(op) => Ok(op), Self::Fake(_) => Err(RuntimeError { line: 0, op: self.clone(), diff --git a/mps-interpreter/src/lang/sorter.rs b/mps-interpreter/src/lang/sorter.rs index 82bffdb..ffecba6 100644 --- a/mps-interpreter/src/lang/sorter.rs +++ b/mps-interpreter/src/lang/sorter.rs @@ -103,7 +103,10 @@ impl Iterator for MpsSortStatement { } fn size_hint(&self) -> (usize, Option) { - self.iterable.try_real_ref().map(|x| x.size_hint()).unwrap_or((0, None)) + self.iterable + .try_real_ref() + .map(|x| x.size_hint()) + .unwrap_or((0, None)) } } diff --git a/mps-interpreter/src/lang/vocabulary/empty.rs b/mps-interpreter/src/lang/vocabulary/empty.rs index 2862d78..e278db7 100644 --- a/mps-interpreter/src/lang/vocabulary/empty.rs +++ b/mps-interpreter/src/lang/vocabulary/empty.rs @@ -24,9 +24,7 @@ impl Display for EmptyStatement { impl std::clone::Clone for EmptyStatement { fn clone(&self) -> Self { - Self { - context: None, - } + Self { context: None } } } @@ -70,16 +68,13 @@ impl MpsFunctionFactory for EmptyFunctionFactory { fn build_function_params( &self, _name: String, - #[allow(unused_variables)] - tokens: &mut VecDeque, + #[allow(unused_variables)] tokens: &mut VecDeque, _dict: &MpsLanguageDictionary, ) -> Result { // empty() #[cfg(debug_assertions)] assert_empty(tokens)?; - Ok(EmptyStatement { - context: None, - }) + Ok(EmptyStatement { context: None }) } } @@ -89,4 +84,3 @@ pub type EmptyStatementFactory = MpsFunctionStatementFactory EmptyStatementFactory { EmptyStatementFactory::new(EmptyFunctionFactory) } - diff --git a/mps-interpreter/src/lang/vocabulary/files.rs b/mps-interpreter/src/lang/vocabulary/files.rs index 47b3a41..11377b9 100644 --- a/mps-interpreter/src/lang/vocabulary/files.rs +++ b/mps-interpreter/src/lang/vocabulary/files.rs @@ -97,7 +97,10 @@ impl Iterator for FilesStatement { } fn size_hint(&self) -> (usize, Option) { - self.file_iter.as_ref().map(|x| x.size_hint()).unwrap_or((0, None)) + self.file_iter + .as_ref() + .map(|x| x.size_hint()) + .unwrap_or((0, None)) } } diff --git a/mps-interpreter/src/lang/vocabulary/repeat.rs b/mps-interpreter/src/lang/vocabulary/repeat.rs index e19535c..5c19e05 100644 --- a/mps-interpreter/src/lang/vocabulary/repeat.rs +++ b/mps-interpreter/src/lang/vocabulary/repeat.rs @@ -197,9 +197,8 @@ impl MpsOp for RepeatStatement { return Err(RuntimeError { line: 0, op: PseudoOp::from_printable(self), - msg: - "Cannot reset part way through repeat when inner statement is not resetable" - .to_string(), + msg: "Cannot reset part way through repeat when inner statement is not resetable" + .to_string(), }); } Ok(()) diff --git a/mps-interpreter/src/lang/vocabulary/reset.rs b/mps-interpreter/src/lang/vocabulary/reset.rs index 2830223..0904a64 100644 --- a/mps-interpreter/src/lang/vocabulary/reset.rs +++ b/mps-interpreter/src/lang/vocabulary/reset.rs @@ -45,7 +45,7 @@ impl Iterator for ResetStatement { Err(e) => return Some(Err(e)), }; match inner.reset() { - Ok(_) => {}, + Ok(_) => {} Err(e) => return Some(Err(e)), }; } @@ -86,8 +86,7 @@ impl MpsFunctionFactory for ResetFunctionFactory { fn build_function_params( &self, _name: String, - #[allow(unused_variables)] - tokens: &mut VecDeque, + #[allow(unused_variables)] tokens: &mut VecDeque, dict: &MpsLanguageDictionary, ) -> Result { // reset(var) @@ -106,4 +105,3 @@ pub type ResetStatementFactory = MpsFunctionStatementFactory ResetStatementFactory { ResetStatementFactory::new(ResetFunctionFactory) } - diff --git a/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs b/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs index 582dd41..68311ef 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs @@ -39,14 +39,19 @@ impl BlissNextSorter { } } - fn algorithm(mut items: VecDeque, results: Sender>>) { + fn algorithm( + mut items: VecDeque, + results: Sender>>, + ) { let mut song_cache: Option<(Song, String)> = None; let items_len = items.len(); for i in 0..items_len { let item = items.pop_front().unwrap(); if let Some(MpsTypePrimitive::String(path)) = item.field("filename") { - if let Err(_) = results.send(Some(Ok(item.clone()))) {break;} - if i+2 < items_len { + if let Err(_) = results.send(Some(Ok(item.clone()))) { + break; + } + if i + 2 < items_len { let target_song = if let Some((_, ref cached_filename)) = song_cache { if cached_filename == path { Ok(song_cache.take().unwrap().0) @@ -67,14 +72,16 @@ impl BlissNextSorter { Err(e) => { results.send(Some(Err(e))).unwrap_or(()); break; - }, + } Ok((next_song, index)) => { if let Some(next_song) = next_song { if index != 0 { items.swap(0, index); } song_cache = Some((next_song, path.to_owned())); - } else {break;} + } else { + break; + } } } } @@ -83,7 +90,10 @@ impl BlissNextSorter { results.send(None).unwrap_or(()); } - fn find_best(items: &VecDeque, target: Song) -> Result<(Option, usize), bliss_audio::BlissError> { + fn find_best( + items: &VecDeque, + target: Song, + ) -> Result<(Option, usize), bliss_audio::BlissError> { let mut best = None; let mut best_index = 0; let mut best_distance = f32::MAX; @@ -94,15 +104,11 @@ impl BlissNextSorter { let result_chann = tx.clone(); let target_clone = target.clone(); let path_clone = path.to_owned(); - std::thread::spawn(move || { - match Song::new(path_clone) { - Err(e) => result_chann - .send(Err(e)) - .unwrap_or(()), - Ok(song) => result_chann - .send(Ok((i, target_clone.distance(&song), song))) - .unwrap_or(()), - } + std::thread::spawn(move || match Song::new(path_clone) { + Err(e) => result_chann.send(Err(e)).unwrap_or(()), + Ok(song) => result_chann + .send(Ok((i, target_clone.distance(&song), song))) + .unwrap_or(()), }); threads_spawned += 1; } @@ -115,7 +121,9 @@ impl BlissNextSorter { best_index = index; best_distance = distance; } - } else {break;} + } else { + break; + } } Ok((best, best_index)) } @@ -203,7 +211,9 @@ pub struct BlissNextSorterFactory; impl MpsSorterFactory for BlissNextSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - tokens.len() == 2 && check_name("advanced", tokens[0]) && check_name("bliss_next", tokens[1]) + tokens.len() == 2 + && check_name("advanced", tokens[0]) + && check_name("bliss_next", tokens[1]) } fn build_sorter( @@ -217,7 +227,8 @@ impl MpsSorterFactory for BlissNextSorterFactory { } } -pub type BlissNextSorterStatementFactory = MpsSortStatementFactory; +pub type BlissNextSorterStatementFactory = + MpsSortStatementFactory; #[inline(always)] pub fn bliss_next_sort() -> BlissNextSorterStatementFactory { diff --git a/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs b/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs index ff85c33..347c02e 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs @@ -210,7 +210,9 @@ pub struct BlissSorterFactory; impl MpsSorterFactory for BlissSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - tokens.len() == 2 && check_name("advanced", tokens[0]) && check_name("bliss_first", tokens[1]) + tokens.len() == 2 + && check_name("advanced", tokens[0]) + && check_name("bliss_first", tokens[1]) } fn build_sorter( diff --git a/mps-interpreter/src/lang/vocabulary/sorters/mod.rs b/mps-interpreter/src/lang/vocabulary/sorters/mod.rs index 59f67a6..d9f42e7 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/mod.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/mod.rs @@ -1,11 +1,15 @@ -mod bliss_sorter; mod bliss_next_sorter; +mod bliss_sorter; mod empty_sorter; mod field_sorter; mod shuffle; +pub use bliss_next_sorter::{ + bliss_next_sort, BlissNextSorter, BlissNextSorterFactory, BlissNextSorterStatementFactory, +}; pub use bliss_sorter::{bliss_sort, BlissSorter, BlissSorterFactory, BlissSorterStatementFactory}; -pub use bliss_next_sorter::{bliss_next_sort, BlissNextSorter, BlissNextSorterFactory, BlissNextSorterStatementFactory}; pub use empty_sorter::{empty_sort, EmptySorter, EmptySorterFactory, EmptySorterStatementFactory}; pub use field_sorter::{field_sort, FieldSorter, FieldSorterFactory, FieldSorterStatementFactory}; -pub use shuffle::{shuffle_sort, ShuffleSorter, ShuffleSorterFactory, ShuffleSorterStatementFactory}; +pub use shuffle::{ + shuffle_sort, ShuffleSorter, ShuffleSorterFactory, ShuffleSorterStatementFactory, +}; diff --git a/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs b/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs index 449ed48..467b621 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs @@ -3,16 +3,16 @@ use std::fmt::{Debug, Display, Error, Formatter}; use rand::{thread_rng, Rng}; +use crate::lang::utility::{assert_name, check_name}; use crate::lang::{MpsIteratorItem, MpsLanguageDictionary, MpsOp}; use crate::lang::{MpsSortStatementFactory, MpsSorter, MpsSorterFactory}; use crate::lang::{RuntimeError, SyntaxError}; -use crate::lang::utility::{check_name, assert_name}; use crate::processing::OpGetter; use crate::tokens::MpsToken; const RNG_LIMIT_BITMASK: usize = 0xffff; // bits to preserve in RNG -// imposes an upper limit in the name of optimisation which reduces randomness past this point -// this is also an effective item_buf size limit, 2^16 - 1 seems reasonable + // imposes an upper limit in the name of optimisation which reduces randomness past this point + // this is also an effective item_buf size limit, 2^16 - 1 seems reasonable #[derive(Debug, Clone)] pub struct ShuffleSorter; @@ -74,8 +74,9 @@ pub struct ShuffleSorterFactory; impl MpsSorterFactory for ShuffleSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { (tokens.len() == 1 && check_name("shuffle", &tokens[0])) - || - (tokens.len() == 2 && check_name("random", &tokens[0]) && check_name("shuffle", &tokens[1])) + || (tokens.len() == 2 + && check_name("random", &tokens[0]) + && check_name("shuffle", &tokens[1])) } fn build_sorter( @@ -91,7 +92,8 @@ impl MpsSorterFactory for ShuffleSorterFactory { } } -pub type ShuffleSorterStatementFactory = MpsSortStatementFactory; +pub type ShuffleSorterStatementFactory = + MpsSortStatementFactory; #[inline(always)] pub fn shuffle_sort() -> ShuffleSorterStatementFactory { diff --git a/mps-interpreter/src/music/tag.rs b/mps-interpreter/src/music/tag.rs index a1e182a..99646b2 100644 --- a/mps-interpreter/src/music/tag.rs +++ b/mps-interpreter/src/music/tag.rs @@ -33,7 +33,8 @@ impl Tags { self.data .get("TITLE") .unwrap_or(&TagType::Unknown) - .str().map(|s| s.to_string()) + .str() + .map(|s| s.to_string()) .unwrap_or_else(|| self.default_title()) } @@ -46,7 +47,8 @@ impl Tags { .unwrap_or(""); self.filename .file_name() - .and_then(|file| file.to_str()).map(|file| file.replacen(&format!(".{}", extension), "", 1)) + .and_then(|file| file.to_str()) + .map(|file| file.replacen(&format!(".{}", extension), "", 1)) .unwrap_or("Unknown Title".into()) } @@ -55,7 +57,8 @@ impl Tags { self.data .get("ARTIST") .unwrap_or(&TagType::Unknown) - .str().map(|s| s.to_string()) + .str() + .map(|s| s.to_string()) } #[inline] @@ -63,7 +66,8 @@ impl Tags { self.data .get("ALBUM") .unwrap_or(&TagType::Unknown) - .str().map(|s| s.to_string()) + .str() + .map(|s| s.to_string()) } #[inline] @@ -71,7 +75,8 @@ impl Tags { self.data .get("GENRE") .unwrap_or(&TagType::Unknown) - .str().map(|s| s.to_string()) + .str() + .map(|s| s.to_string()) } #[inline] diff --git a/mps-interpreter/src/processing/filesystem.rs b/mps-interpreter/src/processing/filesystem.rs index bfc3fb9..ac4d56a 100644 --- a/mps-interpreter/src/processing/filesystem.rs +++ b/mps-interpreter/src/processing/filesystem.rs @@ -68,7 +68,10 @@ impl Display for FileIter { f, "root=`{}`, pattern={}, recursive={}", self.root.to_str().unwrap_or(""), - self.pattern.as_ref().map(|re| re.to_string()).unwrap_or("[none]".to_string()), + self.pattern + .as_ref() + .map(|re| re.to_string()) + .unwrap_or("[none]".to_string()), self.recursive ) } @@ -107,7 +110,9 @@ impl FileIter { op: op(), msg: format!("Regex compile error: {}", e), })?) - } else {None}; + } else { + None + }; let tags_re = Regex::new(DEFAULT_REGEX).map_err(|e| RuntimeError { line: 0, op: op(), @@ -155,7 +160,6 @@ impl FileIter { let capture_names = self.tags_pattern.capture_names(); self.populate_item_impl(path, path_str, captures, capture_names) } - } #[cfg(feature = "music_library")] @@ -232,9 +236,7 @@ impl FileIter { if let Some(captures) = captures { for name_maybe in capture_names { if let Some(name) = name_maybe { - if let Some(value) = captures - .name(name).map(|m| m.as_str().to_string()) - { + if let Some(value) = captures.name(name).map(|m| m.as_str().to_string()) { item.set_field(name, MpsTypePrimitive::parse(value)); } } @@ -298,7 +300,7 @@ impl Iterator for FileIter { self.dir_iters.push(dir_iter); return Some(Ok(item)); } - }, + } Err(e) => { self.dir_iters.push(dir_iter); return Some(Err(format!("Path read error: {}", e))); diff --git a/mps-interpreter/src/processing/sql.rs b/mps-interpreter/src/processing/sql.rs index c0714ac..8997c9d 100644 --- a/mps-interpreter/src/processing/sql.rs +++ b/mps-interpreter/src/processing/sql.rs @@ -248,7 +248,8 @@ impl std::convert::TryInto for SqliteSettings { fn try_into(self) -> Result { let music_path = self - .music_path.map(std::path::PathBuf::from) + .music_path + .map(std::path::PathBuf::from) .unwrap_or_else(crate::lang::utility::music_folder); let sqlite_path = self .db_path diff --git a/mps-interpreter/tests/single_line.rs b/mps-interpreter/tests/single_line.rs index cdd3c16..5b6e954 100644 --- a/mps-interpreter/tests/single_line.rs +++ b/mps-interpreter/tests/single_line.rs @@ -379,20 +379,12 @@ fn execute_blissnextsort_line() -> Result<(), Box> { #[test] fn execute_emptyfn_line() -> Result<(), Box> { - execute_single_line( - "empty()", - true, - true, - ) + execute_single_line("empty()", true, true) } #[test] fn execute_resetfn_line() -> Result<(), Box> { - execute_single_line( - "reset(empty())", - true, - true, - ) + execute_single_line("reset(empty())", true, true) } #[test] @@ -407,9 +399,5 @@ fn execute_shufflesort_line() -> Result<(), Box> { false, true, )?; - execute_single_line( - "empty()~(shuffle)", - true, - true, - ) + execute_single_line("empty()~(shuffle)", true, true) } diff --git a/mps-m3u8/src/cli.rs b/mps-m3u8/src/cli.rs index 03feaed..707a4e5 100644 --- a/mps-m3u8/src/cli.rs +++ b/mps-m3u8/src/cli.rs @@ -12,7 +12,7 @@ pub struct CliArgs { /// Parse input as MPS instead of as filename #[clap(long)] - pub raw: bool + pub raw: bool, } pub fn parse() -> CliArgs { diff --git a/mps-m3u8/src/main.rs b/mps-m3u8/src/main.rs index abc6f5a..b61a379 100644 --- a/mps-m3u8/src/main.rs +++ b/mps-m3u8/src/main.rs @@ -6,8 +6,8 @@ mod cli; use std::fs::File; -use std::path::Path; use std::io::{BufReader, BufWriter, Cursor}; +use std::path::Path; use m3u8_rs::{MediaPlaylist, MediaSegment}; @@ -34,7 +34,7 @@ fn main() { match item { Ok(music) => { if let Some(filename) = - music.field("filename").and_then(|x| x.to_owned().to_str()) + music.field("filename").and_then(|x| x.to_owned().to_str()) { playlist.segments.push(MediaSegment { uri: filename, @@ -44,7 +44,7 @@ fn main() { } else { skipped_count += 1; } - }, + } Err(e) => eprintln!("{}", e), } } @@ -57,7 +57,7 @@ fn main() { match item { Ok(music) => { if let Some(filename) = - music.field("filename").and_then(|x| x.to_owned().to_str()) + music.field("filename").and_then(|x| x.to_owned().to_str()) { playlist.segments.push(MediaSegment { uri: filename, @@ -67,13 +67,16 @@ fn main() { } else { skipped_count += 1; } - }, + } Err(e) => eprintln!("{}", e), } } } if skipped_count != 0 { - eprintln!("Skipped {} items due to missing `filename` field", skipped_count); + eprintln!( + "Skipped {} items due to missing `filename` field", + skipped_count + ); } if let Err(e) = playlist.write_to(&mut out_file) { eprintln!("Playlist save error: {}", e); diff --git a/mps-player/src/os_controls.rs b/mps-player/src/os_controls.rs index bd374ac..654b019 100644 --- a/mps-player/src/os_controls.rs +++ b/mps-player/src/os_controls.rs @@ -25,7 +25,10 @@ pub struct SystemControlWrapper { /// OS-specific APIs for media controls. /// Currently only Linux (dbus) is supported. -#[cfg(any(not(feature = "os-controls"), not(all(target_os = "linux", feature = "os-controls", feature = "mpris-player"))))] +#[cfg(any( + not(feature = "os-controls"), + not(all(target_os = "linux", feature = "os-controls", feature = "mpris-player")) +))] pub struct SystemControlWrapper { #[allow(dead_code)] control: Sender, @@ -221,7 +224,10 @@ impl SystemControlWrapper { } } -#[cfg(any(not(feature = "os-controls"), not(all(target_os = "linux", feature = "os-controls", feature = "mpris-player"))))] +#[cfg(any( + not(feature = "os-controls"), + not(all(target_os = "linux", feature = "os-controls", feature = "mpris-player")) +))] impl SystemControlWrapper { pub fn new(control: Sender) -> Self { Self { diff --git a/mps-player/src/player.rs b/mps-player/src/player.rs index 2262bac..ed4ee9e 100644 --- a/mps-player/src/player.rs +++ b/mps-player/src/player.rs @@ -50,7 +50,7 @@ impl MpsPlayer { "Field `filename` does not exist on item", )) } - }, + } Err(e) => Err(PlaybackError::from_err(e)), }?; } diff --git a/mps-player/src/player_wrapper.rs b/mps-player/src/player_wrapper.rs index 496aeda..eb491a6 100644 --- a/mps-player/src/player_wrapper.rs +++ b/mps-player/src/player_wrapper.rs @@ -41,7 +41,7 @@ impl MpsPlayerServer { match self.player.enqueue(count) { Err(e) => { self.event.send(PlayerAction::Exception(e)).unwrap(); - }, + } Ok(items) => { for item in items { // notify of new items that have been enqueued diff --git a/src/main.rs b/src/main.rs index 9918805..c86a4ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,13 +64,16 @@ fn main() { .unwrap_or_else(|_| panic!("Abort: Cannot open file `{}`", &script_file2)), ); let runner = MpsRunner::with_stream(script_reader); - + MpsPlayer::new(runner).unwrap() }; if let Some(playlist_file) = &args.playlist { // generate playlist let mut player = player_builder(); - let mut writer = io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| panic!("Abort: Cannot create writeable file `{}`", playlist_file))); + let mut writer = + io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| { + panic!("Abort: Cannot create writeable file `{}`", playlist_file) + })); match player.save_m3u8(&mut writer) { Ok(_) => println!( "Succes: Finished playlist `{}` from script `{}`", diff --git a/src/repl.rs b/src/repl.rs index d116410..f9c129e 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -37,14 +37,17 @@ pub fn repl(args: CliArgs) { let (writer, reader) = channel_io(); let player_builder = move || { let runner = MpsRunner::with_stream(reader); - + MpsPlayer::new(runner).unwrap() }; let mut state = ReplState::new(writer); if let Some(playlist_file) = &args.playlist { println!("Playlist mode (output: `{}`)", playlist_file); let mut player = player_builder(); - let mut playlist_writer = io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| panic!("Abort: Cannot create writeable file `{}`", playlist_file))); + let mut playlist_writer = + io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| { + panic!("Abort: Cannot create writeable file `{}`", playlist_file) + })); read_loop(&args, &mut state, || { match player.save_m3u8(&mut playlist_writer) { Ok(_) => {}