Skip to content

Commit

Permalink
chore: run cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Aug 22, 2023
1 parent edb4d71 commit 6dabccc
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 48 deletions.
13 changes: 2 additions & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,20 @@ use clap::crate_name;
use serde::{Deserialize, Serialize};
use std::fs;

#[derive(Deserialize, Serialize, Debug)]
#[derive(Deserialize, Serialize, Debug, Default)]
#[serde(default)]
pub struct Config {
pub theme: Option<String>,
pub ical: Vec<IcalStyle>,
}

impl Default for Config {
fn default() -> Self {
Config {
theme: None,
ical: vec![],
}
}
}

impl Config {
#[cfg(not(tarpaulin_include))]
pub fn read() -> Config {
match xdg::BaseDirectories::with_prefix(crate_name!()) {
Ok(xdg_dirs) => {
if let Some(config_path) = xdg_dirs.find_config_file("config.toml") {
let config_content = fs::read_to_string(&config_path).unwrap_or_default();
let config_content = fs::read_to_string(config_path).unwrap_or_default();
match toml::from_str(&config_content) {
Ok(config) => return config,
Err(e) => eprintln!("Could not parse config file: {}", e),
Expand Down
10 changes: 1 addition & 9 deletions src/config/theme/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(default)]
pub struct DateStyle {
pub properties: Vec<DateProperty>,
#[serde(flatten)]
pub style: Style,
}
impl Default for DateStyle {
fn default() -> Self {
DateStyle {
properties: vec![],
style: Style::default(),
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub enum StyleType {
Expand Down
2 changes: 1 addition & 1 deletion src/config/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Theme {
if let Some(theme_path) =
xdg_dirs.find_config_file(format!("{}.theme", themename))
{
let theme_content = fs::read_to_string(&theme_path).unwrap_or_default();
let theme_content = fs::read_to_string(theme_path).unwrap_or_default();
match toml::from_str(&theme_content) {
Ok(theme) => return theme,
Err(e) => eprintln!("Could not parse theme file: {}", e),
Expand Down
7 changes: 3 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ impl Context {
StyleType::Light
};

let usersetdate: ChronoDate;
match opts.validate_date() {
Ok(x) => usersetdate = x,
let usersetdate: ChronoDate = match opts.validate_date() {
Ok(x) => x,
Err(x) => return Err(x),
}
};

Ok(Context {
usersetdate,
Expand Down
8 changes: 3 additions & 5 deletions src/events/ics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ impl ReadFromIcsFile for Events {
let path = Path::new(filepath);
if path.is_dir() {
if let Ok(path) = path.read_dir() {
for entry in path {
if let Ok(entry) = entry {
if entry.path().is_file() {
filepaths.push(entry.path());
}
for entry in path.flatten() {
if entry.path().is_file() {
filepaths.push(entry.path());
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl fmt::Display for Event {
f,
"{}: {}",
startformatstring,
self.summary.replace("\\", "")
self.summary.replace('\\', "")
)
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ fn main() {
// mabye we should use a pointer instead of cloning the style?
for icalstyle in &ctx.config.ical {
let mut icsevents = Events::read_from_ics_file(&icalstyle.file);
icsevents = icsevents
.into_iter()
.filter(|event| event.in_range(daterangebegin, daterangeend))
.collect();
icsevents.retain(|event| event.in_range(daterangebegin, daterangeend));
for event in icsevents {
ctx.eventstuple.push((event, icalstyle.style.clone()));
}
Expand Down
22 changes: 9 additions & 13 deletions src/output/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ impl Date<'_> {

impl fmt::Display for Date<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let dateformat: String;

if self.ctx.opts.julian {
dateformat = format!("{:>3}", self.date.format("%j"));
let dateformat: String = if self.ctx.opts.julian {
format!("{:>3}", self.date.format("%j"))
} else {
dateformat = format!("{:>2}", self.date.format("%e"));
}
format!("{:>2}", self.date.format("%e"))
};

let mut styles: Vec<Style> = self
.ctx
.theme
.date
.to_vec()
.iter()
.cloned()
.into_iter()
.filter(|datestyle| self.satisfy_all(&datestyle.properties))
.map(|datestyle| datestyle.style)
Expand All @@ -78,12 +77,9 @@ impl fmt::Display for Date<'_> {
}
}

styles = styles
.into_iter()
.filter(|style| {
style.styletype == self.ctx.styletype || style.styletype == StyleType::None
})
.collect();
styles.retain(|style| {
style.styletype == self.ctx.styletype || style.styletype == StyleType::None
});

styles.sort_by(|a, b| a.weight.cmp(&b.weight));
let mut stylenames = vec![];
Expand Down

0 comments on commit 6dabccc

Please sign in to comment.