Use variables directly inside format strings
Most systems should have an up to date Rust compiler by now, so we should be fine.
This commit is contained in:
@@ -90,12 +90,12 @@ pub enum SeekDirection {
|
|||||||
impl fmt::Display for SeekDirection {
|
impl fmt::Display for SeekDirection {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let repr = match self {
|
let repr = match self {
|
||||||
SeekDirection::Absolute(pos) => format!("{}", pos),
|
SeekDirection::Absolute(pos) => format!("{pos}"),
|
||||||
SeekDirection::Relative(delta) => {
|
SeekDirection::Relative(delta) => {
|
||||||
format!("{}{}", if delta > &0 { "+" } else { "" }, delta)
|
format!("{}{}", if delta > &0 { "+" } else { "" }, delta)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
write!(f, "{}", repr)
|
write!(f, "{repr}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ impl fmt::Display for InsertSource {
|
|||||||
InsertSource::Clipboard => "".into(),
|
InsertSource::Clipboard => "".into(),
|
||||||
InsertSource::Input(url) => url.to_string(),
|
InsertSource::Input(url) => url.to_string(),
|
||||||
};
|
};
|
||||||
write!(f, "{}", repr)
|
write!(f, "{repr}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,12 +315,12 @@ impl fmt::Display for CommandParseError {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use CommandParseError::*;
|
use CommandParseError::*;
|
||||||
let formatted = match self {
|
let formatted = match self {
|
||||||
NoSuchCommand { cmd } => format!("No such command \"{}\"", cmd),
|
NoSuchCommand { cmd } => format!("No such command \"{cmd}\""),
|
||||||
InsufficientArgs { cmd, hint } => {
|
InsufficientArgs { cmd, hint } => {
|
||||||
if let Some(hint_str) = hint {
|
if let Some(hint_str) = hint {
|
||||||
format!("\"{}\" requires additional arguments: {}", cmd, hint_str)
|
format!("\"{cmd}\" requires additional arguments: {hint_str}")
|
||||||
} else {
|
} else {
|
||||||
format!("\"{}\" requires additional arguments", cmd)
|
format!("\"{cmd}\" requires additional arguments")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BadEnumArg { arg, accept } => {
|
BadEnumArg { arg, accept } => {
|
||||||
@@ -330,9 +330,9 @@ impl fmt::Display for CommandParseError {
|
|||||||
accept.join("|")
|
accept.join("|")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ArgParseError { arg, err } => format!("Error with argument \"{}\": {}", arg, err),
|
ArgParseError { arg, err } => format!("Error with argument \"{arg}\": {err}"),
|
||||||
};
|
};
|
||||||
write!(f, "{}", formatted)
|
write!(f, "{formatted}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ pub struct Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
pub fn new(filename: &str) -> Self {
|
pub fn new(filename: &str) -> Self {
|
||||||
let values = load(filename).unwrap_or_else(|e| {
|
let values = load(filename).unwrap_or_else(|e| {
|
||||||
eprintln!("could not load config: {}", e);
|
eprintln!("could not load config: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ fn credentials_prompt(error_message: Option<String>) -> Result<Credentials, Stri
|
|||||||
if let Some(message) = error_message {
|
if let Some(message) = error_message {
|
||||||
let mut siv = cursive::default();
|
let mut siv = cursive::default();
|
||||||
let dialog = cursive::views::Dialog::around(cursive::views::TextView::new(format!(
|
let dialog = cursive::views::Dialog::around(cursive::views::TextView::new(format!(
|
||||||
"Connection error:\n{}",
|
"Connection error:\n{message}"
|
||||||
message
|
|
||||||
)))
|
)))
|
||||||
.button("Ok", |s| s.quit());
|
.button("Ok", |s| s.quit());
|
||||||
siv.add_layer(dialog);
|
siv.add_layer(dialog);
|
||||||
@@ -109,7 +108,7 @@ fn register_backtrace_panic_handler() {
|
|||||||
path.push("backtrace.log");
|
path.push("backtrace.log");
|
||||||
if let Ok(mut file) = File::create(path) {
|
if let Ok(mut file) = File::create(path) {
|
||||||
writeln!(file, "{}", backtrace::Backtrace::force_capture()).unwrap_or_default();
|
writeln!(file, "{}", backtrace::Backtrace::force_capture()).unwrap_or_default();
|
||||||
writeln!(file, "{}", panic_info).unwrap_or_default();
|
writeln!(file, "{panic_info}").unwrap_or_default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@@ -197,7 +196,7 @@ fn main() -> Result<(), String> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
while let Err(error) = spotify::Spotify::test_credentials(credentials.clone()) {
|
while let Err(error) = spotify::Spotify::test_credentials(credentials.clone()) {
|
||||||
let error_msg = format!("{}", error);
|
let error_msg = format!("{error}");
|
||||||
credentials = credentials_prompt(Some(error_msg))?;
|
credentials = credentials_prompt(Some(error_msg))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ impl ListItem for Album {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||||
format!("{}", self)
|
format!("{self}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_right(&self, library: Arc<Library>) -> String {
|
fn display_right(&self, library: Arc<Library>) -> String {
|
||||||
@@ -289,7 +289,7 @@ impl ListItem for Album {
|
|||||||
fn share_url(&self) -> Option<String> {
|
fn share_url(&self) -> Option<String> {
|
||||||
self.id
|
self.id
|
||||||
.clone()
|
.clone()
|
||||||
.map(|id| format!("https://open.spotify.com/album/{}", id))
|
.map(|id| format!("https://open.spotify.com/album/{id}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn artists(&self) -> Option<Vec<Artist>> {
|
fn artists(&self) -> Option<Vec<Artist>> {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ impl ListItem for Artist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||||
format!("{}", self)
|
format!("{self}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_right(&self, library: Arc<Library>) -> String {
|
fn display_right(&self, library: Arc<Library>) -> String {
|
||||||
@@ -115,7 +115,7 @@ impl ListItem for Artist {
|
|||||||
"".into()
|
"".into()
|
||||||
};
|
};
|
||||||
|
|
||||||
format!("{}{}", followed, tracks)
|
format!("{followed}{tracks}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn play(&mut self, queue: Arc<Queue>) {
|
fn play(&mut self, queue: Arc<Queue>) {
|
||||||
@@ -199,7 +199,7 @@ impl ListItem for Artist {
|
|||||||
fn share_url(&self) -> Option<String> {
|
fn share_url(&self) -> Option<String> {
|
||||||
self.id
|
self.id
|
||||||
.clone()
|
.clone()
|
||||||
.map(|id| format!("https://open.spotify.com/artist/{}", id))
|
.map(|id| format!("https://open.spotify.com/artist/{id}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ impl Episode {
|
|||||||
pub fn duration_str(&self) -> String {
|
pub fn duration_str(&self) -> String {
|
||||||
let minutes = self.duration / 60_000;
|
let minutes = self.duration / 60_000;
|
||||||
let seconds = (self.duration / 1000) % 60;
|
let seconds = (self.duration / 1000) % 60;
|
||||||
format!("{:02}:{:02}", minutes, seconds)
|
format!("{minutes:02}:{seconds:02}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl Playable {
|
|||||||
let duration = self.duration();
|
let duration = self.duration();
|
||||||
let minutes = duration / 60_000;
|
let minutes = duration / 60_000;
|
||||||
let seconds = (duration / 1000) % 60;
|
let seconds = (duration / 1000) % 60;
|
||||||
format!("{:02}:{:02}", minutes, seconds)
|
format!("{minutes:02}:{seconds:02}")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_listitem(&self) -> Box<dyn ListItem> {
|
pub fn as_listitem(&self) -> Box<dyn ListItem> {
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ impl ListItem for Playlist {
|
|||||||
.map(|t| t.len())
|
.map(|t| t.len())
|
||||||
.unwrap_or(self.num_tracks);
|
.unwrap_or(self.num_tracks);
|
||||||
|
|
||||||
format!("{}{:>4} tracks", saved, num_tracks)
|
format!("{saved}{num_tracks:>4} tracks")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn play(&mut self, queue: Arc<Queue>) {
|
fn play(&mut self, queue: Arc<Queue>) {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl ListItem for Show {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||||
format!("{}", self)
|
format!("{self}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_right(&self, library: Arc<Library>) -> String {
|
fn display_right(&self, library: Arc<Library>) -> String {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl Track {
|
|||||||
pub fn duration_str(&self) -> String {
|
pub fn duration_str(&self) -> String {
|
||||||
let minutes = self.duration / 60_000;
|
let minutes = self.duration / 60_000;
|
||||||
let seconds = (self.duration / 1000) % 60;
|
let seconds = (self.duration / 1000) % 60;
|
||||||
format!("{:02}:{:02}", minutes, seconds)
|
format!("{minutes:02}:{seconds:02}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ impl ListItem for Track {
|
|||||||
if left != default {
|
if left != default {
|
||||||
Playable::format(&Playable::Track(self.clone()), &left, library)
|
Playable::format(&Playable::Track(self.clone()), &left, library)
|
||||||
} else {
|
} else {
|
||||||
format!("{}", self)
|
format!("{self}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ impl ListItem for Track {
|
|||||||
fn share_url(&self) -> Option<String> {
|
fn share_url(&self) -> Option<String> {
|
||||||
self.id
|
self.id
|
||||||
.clone()
|
.clone()
|
||||||
.map(|id| format!("https://open.spotify.com/track/{}", id))
|
.map(|id| format!("https://open.spotify.com/track/{id}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn album(&self, queue: Arc<Queue>) -> Option<Album> {
|
fn album(&self, queue: Arc<Queue>) -> Option<Album> {
|
||||||
|
|||||||
@@ -566,7 +566,7 @@ fn run_dbus_server(
|
|||||||
let captures = regex.captures(s).unwrap();
|
let captures = regex.captures(s).unwrap();
|
||||||
let uri_type = &captures[2];
|
let uri_type = &captures[2];
|
||||||
let id = &captures[3];
|
let id = &captures[3];
|
||||||
format!("spotify:{}:{}", uri_type, id)
|
format!("spotify:{uri_type}:{id}")
|
||||||
}else {
|
}else {
|
||||||
s.to_string()
|
s.to_string()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ impl Serializer for TomlSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write<P: AsRef<Path>, T: serde::Serialize>(&self, path: P, value: T) -> Result<T, String> {
|
fn write<P: AsRef<Path>, T: serde::Serialize>(&self, path: P, value: T) -> Result<T, String> {
|
||||||
let content = toml::to_string_pretty(&value)
|
let content =
|
||||||
.map_err(|e| format!("Failed serializing value: {}", e))?;
|
toml::to_string_pretty(&value).map_err(|e| format!("Failed serializing value: {e}"))?;
|
||||||
fs::write(path.as_ref(), content)
|
fs::write(path.as_ref(), content)
|
||||||
.map(|_| value)
|
.map(|_| value)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub fn read_share() -> Option<String> {
|
|||||||
string = None
|
string = None
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("{}", err);
|
eprintln!("{err}");
|
||||||
string = None
|
string = None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,10 +78,8 @@ impl Worker {
|
|||||||
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
||||||
let client_id = config::CLIENT_ID;
|
let client_id = config::CLIENT_ID;
|
||||||
let scopes = "user-read-private,playlist-read-private,playlist-read-collaborative,playlist-modify-public,playlist-modify-private,user-follow-modify,user-follow-read,user-library-read,user-library-modify,user-top-read,user-read-recently-played";
|
let scopes = "user-read-private,playlist-read-private,playlist-read-collaborative,playlist-modify-public,playlist-modify-private,user-follow-modify,user-follow-read,user-library-read,user-library-modify,user-top-read,user-read-recently-played";
|
||||||
let url = format!(
|
let url =
|
||||||
"hm://keymaster/token/authenticated?client_id={}&scope={}",
|
format!("hm://keymaster/token/authenticated?client_id={client_id}&scope={scopes}");
|
||||||
client_id, scopes
|
|
||||||
);
|
|
||||||
Box::pin(
|
Box::pin(
|
||||||
self.session
|
self.session
|
||||||
.mercury()
|
.mercury()
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ impl View for Layout {
|
|||||||
// back button + title
|
// back button + title
|
||||||
if !self.is_current_stack_empty() {
|
if !self.is_current_stack_empty() {
|
||||||
printer.with_color(ColorStyle::title_secondary(), |printer| {
|
printer.with_color(ColorStyle::title_secondary(), |printer| {
|
||||||
printer.print((1, 0), &format!("< {}", screen_title));
|
printer.print((1, 0), &format!("< {screen_title}"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,10 +255,7 @@ impl View for Layout {
|
|||||||
|
|
||||||
printer.with_color(style, |printer| {
|
printer.with_color(style, |printer| {
|
||||||
printer.print_hline((0, printer.size.y - cmdline_height), printer.size.x, " ");
|
printer.print_hline((0, printer.size.y - cmdline_height), printer.size.x, " ");
|
||||||
printer.print(
|
printer.print((0, printer.size.y - cmdline_height), &format!("ERROR: {e}"));
|
||||||
(0, printer.size.y - cmdline_height),
|
|
||||||
&format!("ERROR: {}", e),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ impl ViewWrapper for LibraryView {
|
|||||||
impl ViewExt for LibraryView {
|
impl ViewExt for LibraryView {
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
if let Some(name) = &self.display_name {
|
if let Some(name) = &self.display_name {
|
||||||
format!("Library of {}", name)
|
format!("Library of {name}")
|
||||||
} else {
|
} else {
|
||||||
"Library".to_string()
|
"Library".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub fn format_duration(d: &std::time::Duration) -> String {
|
|||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let mut append_unit = |value, unit| {
|
let mut append_unit = |value, unit| {
|
||||||
if value > 0 {
|
if value > 0 {
|
||||||
let _ = write!(s, "{}{}", value, unit);
|
let _ = write!(s, "{value}{unit}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user