Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Jun 17, 2024
1 parent aeaa273 commit 88ce314
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions crates/adapter/src/model/app/area_of_life.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cawr_domain::area_of_life as aol;
use std::str::FromStr;
use std::{fmt, str::FromStr};

use thiserror::Error;

use cawr_domain::area_of_life as aol;

/// This is the public ID of an area of life.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Id(u64);
Expand Down Expand Up @@ -36,9 +38,9 @@ impl FromStr for Id {
}
}

impl ToString for Id {
fn to_string(&self) -> String {
self.0.to_string()
impl fmt::Display for Id {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}

Expand Down
12 changes: 7 additions & 5 deletions crates/adapter/src/model/app/thought.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cawr_domain::thought;
use std::str::FromStr;
use std::{fmt, str::FromStr};

use thiserror::Error;

use cawr_domain::thought;

/// This is the public ID of a thought.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Id(u64);
Expand Down Expand Up @@ -36,9 +38,9 @@ impl FromStr for Id {
}
}

impl ToString for Id {
fn to_string(&self) -> String {
self.0.to_string()
impl fmt::Display for Id {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ cawr-domain = "=0.0.0"

# External dependencies
log = "0.4"
parking_lot = "0.12"
thiserror = "1.0"
11 changes: 6 additions & 5 deletions crates/application/src/usecase/thought/create.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::collections::HashSet;

use thiserror::Error;

use crate::{
gateway::repository::{
area_of_life,
Expand All @@ -13,8 +17,6 @@ use cawr_domain::{
area_of_life as aol,
thought::{Id, Thought, Title},
};
use std::collections::HashSet;
use thiserror::Error;

#[derive(Debug)]
pub struct Request {
Expand Down Expand Up @@ -98,7 +100,7 @@ where
mod tests {
use super::*;
use crate::gateway::repository::thought::{DeleteError, GetAllError, GetError};
use std::sync::RwLock;
use parking_lot::RwLock;

#[derive(Default)]
struct MockRepo {
Expand All @@ -107,7 +109,7 @@ mod tests {

impl thought::Repo for MockRepo {
fn save(&self, record: Record) -> Result<(), SaveError> {
*self.thought.write().unwrap() = Some(record);
*self.thought.write() = Some(record);
Ok(())
}
fn get(&self, _: Id) -> Result<Record, GetError> {
Expand Down Expand Up @@ -157,7 +159,6 @@ mod tests {
assert_eq!(
repo.thought
.read()
.unwrap()
.as_ref()
.unwrap()
.thought
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn run<D>(db: Arc<D>, cmd: Command)
where
D: Db,
{
let app_api = Api::new(db, Presenter::default());
let app_api = Api::new(db, Presenter);

match cmd {
Command::Create { title } => {
Expand Down
1 change: 1 addition & 0 deletions crates/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cawr-domain = "=0.0.0"
# External dependencies
log = "0.4"
jfs = "0.9"
parking_lot = "0.12"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
Expand Down
19 changes: 5 additions & 14 deletions crates/db/src/in_memory.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::collections::HashMap;

use parking_lot::RwLock;

use cawr_adapter::db::Db;
use cawr_application::{
gateway::repository::{
area_of_life::Record as AreaOfLifeRecord, thought::Record as ThoughtRecord,
},
identifier::{NewId, NewIdError},
};
use std::{collections::HashMap, sync::RwLock};

#[derive(Default)]
pub struct InMemory {
Expand All @@ -24,16 +27,12 @@ mod thought {

impl Repo for InMemory {
fn save(&self, record: Record) -> Result<(), SaveError> {
self.thoughts
.write()
.unwrap()
.insert(record.thought.id(), record);
self.thoughts.write().insert(record.thought.id(), record);
Ok(())
}
fn get(&self, id: Id) -> Result<Record, GetError> {
self.thoughts
.read()
.unwrap()
.get(&id)
.cloned()
.ok_or(GetError::NotFound)
Expand All @@ -42,7 +41,6 @@ mod thought {
Ok(self
.thoughts
.read()
.unwrap()
.iter()
.map(|(_, r)| r)
.cloned()
Expand All @@ -51,7 +49,6 @@ mod thought {
fn delete(&self, id: Id) -> Result<(), DeleteError> {
self.thoughts
.write()
.unwrap()
.remove(&id)
.map(|_| ())
.ok_or(DeleteError::NotFound)
Expand All @@ -63,7 +60,6 @@ mod thought {
let next = self
.thoughts
.read()
.unwrap()
.iter()
.map(|(id, _)| id.to_u64())
.max()
Expand All @@ -85,14 +81,12 @@ mod area_of_life {
fn save(&self, record: Record) -> Result<(), SaveError> {
self.areas_of_life
.write()
.unwrap()
.insert(record.area_of_life.id(), record);
Ok(())
}
fn get(&self, id: Id) -> Result<Record, GetError> {
self.areas_of_life
.read()
.unwrap()
.get(&id)
.cloned()
.ok_or(GetError::NotFound)
Expand All @@ -101,7 +95,6 @@ mod area_of_life {
Ok(self
.areas_of_life
.read()
.unwrap()
.iter()
.map(|(_, r)| r)
.cloned()
Expand All @@ -110,7 +103,6 @@ mod area_of_life {
fn delete(&self, id: Id) -> Result<(), DeleteError> {
self.areas_of_life
.write()
.unwrap()
.remove(&id)
.map(|_| ())
.ok_or(DeleteError::NotFound)
Expand All @@ -122,7 +114,6 @@ mod area_of_life {
let next = self
.areas_of_life
.read()
.unwrap()
.iter()
.map(|(id, _)| id.to_u64())
.max()
Expand Down
2 changes: 1 addition & 1 deletion crates/desktop-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
.enable_all()
.build()
.unwrap();
let app_api = Api::new(db, Presenter::default());
let app_api = Api::new(db, Presenter);
let options = eframe::NativeOptions::default();
eframe::run_native(
TITLE,
Expand Down
2 changes: 1 addition & 1 deletion crates/domain/src/value_object/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<T> Id<T> {

impl<T> Clone for Id<T> {
fn clone(&self) -> Self {
Self::new(self.id)
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/web-server-warp/src/handler/thought/find_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ mod tests {

assert_eq!(err.msg, None);
assert_eq!(err.status, json::StatusCode::INTERNAL_SERVER_ERROR);
assert!(matches!(err.details, None));
assert!(err.details.is_none());
}
}
2 changes: 1 addition & 1 deletion crates/web-server-warp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn run<D>(db: Arc<D>, addr: SocketAddr)
where
D: Db,
{
let web_app_api = Api::new(db, Presenter::default());
let web_app_api = Api::new(db, Presenter);
let api = route::api(web_app_api);
let routes = api.or(webapp::get_index()).or(webapp::get_assets());
warp::serve(routes).run(addr).await;
Expand Down
4 changes: 2 additions & 2 deletions crates/web-server-warp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub fn blank_db() -> Arc<InMemory> {
}

pub fn corrupt_db() -> Arc<CorruptTestDb> {
Arc::new(CorruptTestDb::default())
Arc::new(CorruptTestDb)
}

pub fn app_api<D>(db: Arc<D>) -> AppApi<D>
where
D: Db,
{
Api::new(db, Presenter::default())
Api::new(db, Presenter)
}

#[derive(Default)]
Expand Down

0 comments on commit 88ce314

Please sign in to comment.