Skip to content

Commit

Permalink
Use Rust 1.70, address some of Clippy's advice
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuda committed Aug 10, 2023
1 parent 9fecc03 commit 05ff0d1
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.70.0"
components = ["rustfmt", "clippy"]
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ impl BuildMetaIndex {
file_id: file_id,
title: StringRef(title),
artist: StringRef(track_artist),
duration_seconds: file.duration_seconds as u16,
duration_seconds: file.duration_seconds,
filename: file.filename,
loudness: track_loudness,
};
Expand Down
2 changes: 1 addition & 1 deletion src/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub fn main(
play_queue(
&config.audio_device,
&config.audio_volume_control,
&*state_mutex,
&state_mutex,
decode_thread,
);
println!("Playback done, sleeping ...");
Expand Down
12 changes: 6 additions & 6 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ pub struct Format {
pub bits_per_sample: u32,
}

impl Format {
pub fn default() -> Format {
impl Default for Format {
fn default() -> Format {
Format {
sample_rate: Hertz(44_100),
bits_per_sample: 16,
Expand Down Expand Up @@ -1031,7 +1031,7 @@ fn decode_main(

if should_decode {
let current_index = index.get();
decode_burst(&*current_index, state_mutex, &mut filters);
decode_burst(&current_index, state_mutex, &mut filters);
}

println!("Decoder going to sleep.");
Expand Down Expand Up @@ -1101,7 +1101,7 @@ impl Player {
.spawn(move || {
decode_main(
index_for_decode,
&*state_mutex_for_decode,
&state_mutex_for_decode,
high_pass_cutoff,
);
}).unwrap();
Expand Down Expand Up @@ -1174,8 +1174,8 @@ impl Player {
let album_id = track_id.album_id();
let track = index.get_track(track_id).expect("Can only enqueue existing tracks.");
let album = index.get_album(album_id).expect("Track must belong to album.");
let track_loudness = track.loudness.unwrap_or_else(Lufs::default);
let album_loudness = album.loudness.unwrap_or_else(Lufs::default);
let track_loudness = track.loudness.unwrap_or_default();
let album_loudness = album.loudness.unwrap_or_default();

// If the queue is empty, then the playback thread may be parked,
// so we may need to wake it after enqueuing something.
Expand Down
4 changes: 3 additions & 1 deletion src/prim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ impl Lufs {
.expect("A value of 0.0 LUFS is not allowed, use -0.01 LUFS instead.")
)
}
}

pub fn default() -> Lufs {
impl Default for Lufs {
fn default() -> Lufs {
Lufs(std::num::NonZeroI16::new(-900).unwrap())
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ pub fn run_scan_in_thread(
tx.send(status).unwrap();

let mut loudness_tasks = loudness::TaskQueue::new(
&*index_arc,
&index_arc,
&mut status,
&mut tx,
);
Expand All @@ -653,7 +653,7 @@ pub fn run_scan_in_thread(
// If there are any new or updated albums, regenerate thumbnails for
// those.
crate::thumb_gen::generate_thumbnails(
&*index_arc,
&index_arc,
&db_path,
&mut status,
&mut tx,
Expand Down
2 changes: 1 addition & 1 deletion src/thumb_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ThumbCache {
///
/// See also [`load_from_database`].
pub fn load_from_database_at(db_path: &Path) -> db::Result<ThumbCache> {
let inner = database_utils::connect_readonly(&db_path)?;
let inner = database_utils::connect_readonly(db_path)?;
let mut conn = db::Connection::new(&inner);
let mut tx = conn.begin()?;
let result = ThumbCache::load_from_database(&mut tx)?;
Expand Down
24 changes: 12 additions & 12 deletions src/thumb_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,27 @@ impl<'a> GenThumb<'a> {
// thumbnail become darker, which is especially noticeable for
// covers with white edges, and also shows up as a "pop" in the
// album view when the full-resolution image loads.
.args(&["-background", "black"])
.args(&["-alpha", "remove"])
.args(&["-alpha", "off"])
.args(&["-flatten"])
.args(["-background", "black"])
.args(["-alpha", "remove"])
.args(["-alpha", "off"])
.args(["-flatten"])
// Resize in a linear color space, sRGB is not suitable for it
// because it is nonlinear. "RGB" in ImageMagick is linear.
.args(&["-colorspace", "RGB"])
.args(["-colorspace", "RGB"])
// See also the note about -flatten above. I think Edge is the
// default, but let's be explicit about it.
.args(&["-virtual-pixel", "Edge"])
.args(["-virtual-pixel", "Edge"])
// Lanczos2 is a bit less sharp than Cosine, but less sharp edges
// means that the image compresses better, and less artifacts. But
// still, Lanczos was too blurry in my opinion.
.args(&["-filter", "Cosine"])
.args(["-filter", "Cosine"])
// Twice the size of the thumb in the webinterface, so they appear
// pixel-perfect on a high-DPI display, or on a mobile phone.
.args(&["-distort", "Resize", "140x140!"])
.args(&["-colorspace", "sRGB"])
.args(["-distort", "Resize", "140x140!"])
.args(["-colorspace", "sRGB"])
// Remove EXIF metadata, including the colour profile if there was
// any -- we convert to sRGB anyway.
.args(&["-strip"])
.args(["-strip"])
// Write lossless, we will later compress to jpeg with Guetzli,
// which has a better compressor.
.arg(&out_path)
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'a> GenThumb<'a> {
.map_err(|e| Error::CommandError("Imagemagick's 'convert' failed.", e))?;

let guetzli = Command::new("guetzli")
.args(&["--quality", "97"])
.args(["--quality", "97"])
// Input is the intermediate file.
.arg(&out_path)
// Output is stdout, but guetzli does not understand `-`.
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<'a> GenThumb<'a> {
.map_err(|e| Error::CommandError("Guetzli failed.", e))?;

// Delete the intermediate png file.
std::fs::remove_file(&in_path)?;
std::fs::remove_file(in_path)?;

let mut stdout = child
.stdout
Expand Down
4 changes: 2 additions & 2 deletions src/word_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ impl WordMeta {
/// Return a copy of the word meta, with log-frequency filled in.
fn set_frequency(self, frequency: u64) -> WordMeta {
debug_assert!(frequency > 0, "Frequency must be positive.");
let log2_frequency = 63 - frequency.leading_zeros();
let log2_frequency: u32 = 63 - frequency.leading_zeros();

// The 6-bit log-frequency is at offset 24.
WordMeta(self.0 | ((log2_frequency as u32) << 24))
WordMeta(self.0 | (log2_frequency << 24))
}
}

Expand Down

0 comments on commit 05ff0d1

Please sign in to comment.