Skip to content

Commit

Permalink
[✅ test] Implement clippy warning recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlucasvieira committed Jan 25, 2024
1 parent e5ed5fd commit 17588dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn init(app_config: &AppConfig) -> Result<()> {
})?;

// Create file
std::fs::File::create(&app_config.data_file_path()).with_context(|| {
std::fs::File::create(app_config.data_file_path()).with_context(|| {
format!(
"Could not create file '{}'",
app_config.data_file_path().display()
Expand Down
16 changes: 12 additions & 4 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::app;
use anyhow::{anyhow, Context, Result};
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;
use std::{collections::HashMap, fmt, fs, path::PathBuf};

/// Memo data contains the content of the memo file.
Expand All @@ -21,11 +22,18 @@ impl MemoData {
fn parse(data: String) -> Result<HashMap<u32, String>> {
data.lines()
.filter(|line| !line.is_empty())
.map(|line| vaidate_line(line))
.map(vaidate_line)
.collect()
}
}

/// Implement Default trait for MemoData
impl Default for MemoData {
fn default() -> Self {
Self::new()
}
}

/// Implement DataFile trait for MemoData
impl DataFile for MemoData {
/// Load data from file
Expand Down Expand Up @@ -74,7 +82,7 @@ impl DataFile for MemoData {
.ok_or_else(|| anyhow!("Id '{}' not found", id))?
));
}
return Ok(s);
Ok(s)
}
}

Expand All @@ -99,7 +107,7 @@ pub trait DataFile: fmt::Display {
}

/// Get file path and file name and check if it exists
fn file_exist(file_path: &PathBuf) -> Result<bool> {
fn file_exist(file_path: &Path) -> Result<bool> {
if file_path.exists() {
Ok(true)
} else {
Expand All @@ -126,7 +134,7 @@ pub fn write_file(file_path: &PathBuf, content: &str) -> Result<()> {
let mut temp_file = fs::File::create(&temp_file_path)?;
temp_file.write_all(content.as_bytes())?;

fs::rename(&temp_file_path, &file_path)?;
fs::rename(&temp_file_path, file_path)?;
Ok(())
}

Expand Down

0 comments on commit 17588dd

Please sign in to comment.