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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let repr = match self {
|
||||
SeekDirection::Absolute(pos) => format!("{}", pos),
|
||||
SeekDirection::Absolute(pos) => format!("{pos}"),
|
||||
SeekDirection::Relative(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::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 {
|
||||
use CommandParseError::*;
|
||||
let formatted = match self {
|
||||
NoSuchCommand { cmd } => format!("No such command \"{}\"", cmd),
|
||||
NoSuchCommand { cmd } => format!("No such command \"{cmd}\""),
|
||||
InsufficientArgs { cmd, hint } => {
|
||||
if let Some(hint_str) = hint {
|
||||
format!("\"{}\" requires additional arguments: {}", cmd, hint_str)
|
||||
format!("\"{cmd}\" requires additional arguments: {hint_str}")
|
||||
} else {
|
||||
format!("\"{}\" requires additional arguments", cmd)
|
||||
format!("\"{cmd}\" requires additional arguments")
|
||||
}
|
||||
}
|
||||
BadEnumArg { arg, accept } => {
|
||||
@@ -330,9 +330,9 @@ impl fmt::Display for CommandParseError {
|
||||
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 {
|
||||
pub fn new(filename: &str) -> Self {
|
||||
let values = load(filename).unwrap_or_else(|e| {
|
||||
eprintln!("could not load config: {}", e);
|
||||
eprintln!("could not load config: {e}");
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -85,8 +85,7 @@ fn credentials_prompt(error_message: Option<String>) -> Result<Credentials, Stri
|
||||
if let Some(message) = error_message {
|
||||
let mut siv = cursive::default();
|
||||
let dialog = cursive::views::Dialog::around(cursive::views::TextView::new(format!(
|
||||
"Connection error:\n{}",
|
||||
message
|
||||
"Connection error:\n{message}"
|
||||
)))
|
||||
.button("Ok", |s| s.quit());
|
||||
siv.add_layer(dialog);
|
||||
@@ -109,7 +108,7 @@ fn register_backtrace_panic_handler() {
|
||||
path.push("backtrace.log");
|
||||
if let Ok(mut file) = File::create(path) {
|
||||
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()) {
|
||||
let error_msg = format!("{}", error);
|
||||
let error_msg = format!("{error}");
|
||||
credentials = credentials_prompt(Some(error_msg))?;
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ impl ListItem for Album {
|
||||
}
|
||||
|
||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||
format!("{}", self)
|
||||
format!("{self}")
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
@@ -289,7 +289,7 @@ impl ListItem for Album {
|
||||
fn share_url(&self) -> Option<String> {
|
||||
self.id
|
||||
.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>> {
|
||||
|
||||
@@ -95,7 +95,7 @@ impl ListItem for Artist {
|
||||
}
|
||||
|
||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||
format!("{}", self)
|
||||
format!("{self}")
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
@@ -115,7 +115,7 @@ impl ListItem for Artist {
|
||||
"".into()
|
||||
};
|
||||
|
||||
format!("{}{}", followed, tracks)
|
||||
format!("{followed}{tracks}")
|
||||
}
|
||||
|
||||
fn play(&mut self, queue: Arc<Queue>) {
|
||||
@@ -199,7 +199,7 @@ impl ListItem for Artist {
|
||||
fn share_url(&self) -> Option<String> {
|
||||
self.id
|
||||
.clone()
|
||||
.map(|id| format!("https://open.spotify.com/artist/{}", id))
|
||||
.map(|id| format!("https://open.spotify.com/artist/{id}"))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -25,7 +25,7 @@ impl Episode {
|
||||
pub fn duration_str(&self) -> String {
|
||||
let minutes = self.duration / 60_000;
|
||||
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 minutes = duration / 60_000;
|
||||
let seconds = (duration / 1000) % 60;
|
||||
format!("{:02}:{:02}", minutes, seconds)
|
||||
format!("{minutes:02}:{seconds:02}")
|
||||
}
|
||||
|
||||
pub fn as_listitem(&self) -> Box<dyn ListItem> {
|
||||
|
||||
@@ -216,7 +216,7 @@ impl ListItem for Playlist {
|
||||
.map(|t| t.len())
|
||||
.unwrap_or(self.num_tracks);
|
||||
|
||||
format!("{}{:>4} tracks", saved, num_tracks)
|
||||
format!("{saved}{num_tracks:>4} tracks")
|
||||
}
|
||||
|
||||
fn play(&mut self, queue: Arc<Queue>) {
|
||||
|
||||
@@ -77,7 +77,7 @@ impl ListItem for Show {
|
||||
}
|
||||
|
||||
fn display_left(&self, _library: Arc<Library>) -> String {
|
||||
format!("{}", self)
|
||||
format!("{self}")
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
|
||||
@@ -74,7 +74,7 @@ impl Track {
|
||||
pub fn duration_str(&self) -> String {
|
||||
let minutes = self.duration / 60_000;
|
||||
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 {
|
||||
Playable::format(&Playable::Track(self.clone()), &left, library)
|
||||
} else {
|
||||
format!("{}", self)
|
||||
format!("{self}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ impl ListItem for Track {
|
||||
fn share_url(&self) -> Option<String> {
|
||||
self.id
|
||||
.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> {
|
||||
|
||||
@@ -566,7 +566,7 @@ fn run_dbus_server(
|
||||
let captures = regex.captures(s).unwrap();
|
||||
let uri_type = &captures[2];
|
||||
let id = &captures[3];
|
||||
format!("spotify:{}:{}", uri_type, id)
|
||||
format!("spotify:{uri_type}:{id}")
|
||||
}else {
|
||||
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> {
|
||||
let content = toml::to_string_pretty(&value)
|
||||
.map_err(|e| format!("Failed serializing value: {}", e))?;
|
||||
let content =
|
||||
toml::to_string_pretty(&value).map_err(|e| format!("Failed serializing value: {e}"))?;
|
||||
fs::write(path.as_ref(), content)
|
||||
.map(|_| value)
|
||||
.map_err(|e| {
|
||||
|
||||
@@ -67,7 +67,7 @@ pub fn read_share() -> Option<String> {
|
||||
string = None
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("{}", err);
|
||||
eprintln!("{err}");
|
||||
string = None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +78,8 @@ impl Worker {
|
||||
) -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
||||
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 url = format!(
|
||||
"hm://keymaster/token/authenticated?client_id={}&scope={}",
|
||||
client_id, scopes
|
||||
);
|
||||
let url =
|
||||
format!("hm://keymaster/token/authenticated?client_id={client_id}&scope={scopes}");
|
||||
Box::pin(
|
||||
self.session
|
||||
.mercury()
|
||||
|
||||
@@ -218,7 +218,7 @@ impl View for Layout {
|
||||
// back button + title
|
||||
if !self.is_current_stack_empty() {
|
||||
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.print_hline((0, printer.size.y - cmdline_height), printer.size.x, " ");
|
||||
printer.print(
|
||||
(0, printer.size.y - cmdline_height),
|
||||
&format!("ERROR: {}", e),
|
||||
);
|
||||
printer.print((0, printer.size.y - cmdline_height), &format!("ERROR: {e}"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ impl ViewWrapper for LibraryView {
|
||||
impl ViewExt for LibraryView {
|
||||
fn title(&self) -> String {
|
||||
if let Some(name) = &self.display_name {
|
||||
format!("Library of {}", name)
|
||||
format!("Library of {name}")
|
||||
} else {
|
||||
"Library".to_string()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn format_duration(d: &std::time::Duration) -> String {
|
||||
let mut s = String::new();
|
||||
let mut append_unit = |value, unit| {
|
||||
if value > 0 {
|
||||
let _ = write!(s, "{}{}", value, unit);
|
||||
let _ = write!(s, "{value}{unit}");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user