Any code base that starts to grow in size and complexity will benefit from applying formatting and linting rules. Since I am firmly in the camp of stricter lints == better, I tend to turn Clippy up to 11 pedantic mode.
Turning on a specific set of lints can be done by adding directives at the start of main.rs
, in this case I added #![warn(clippy::pedantic)]
. It is also possible to #![deny(..)]
but this has a drawback: Compilation will not complete, and you might get an incomplete list of findings. We tend to configure CI so that it fails on warnings
anyway, so deny
'ing is not necessary.
The result is the usual conciseness improvements like changing for element in self.elements.iter()
to for element in &self.elements
, and 1 interesting finding about an unused field in the IndexEntry
struct that was added when splitting the blog into a page per entry:
pub struct IndexEntry {
pub title: String,
pub date: NaiveDate,
// ^^^^ unused
pub summary: String,
pub uri: String,
}
The best way to fix this finding? Start using the date! The render function for IndexEntry
now references date
, solving the finding:
impl Element for IndexEntry {
fn render(&self) -> String {
format!(
r#"
<div class="index-entry">
<a href="{uri}">
{title}
<subtitle>{date}</subtitle>
{summary}
</a>
</div>
"#,
uri = self.uri,
title = self.title,
date = self.date.format("%A, %-d %B, %C%y"),
summary = self.summary
)
}
}
The full set of changes