Skip to content

Commit

Permalink
Listen to clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmo14 committed Jun 22, 2020
1 parent 27083ca commit d06a64d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
7 changes: 2 additions & 5 deletions src/bin/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
extern crate log;
extern crate pretty_env_logger;

use std::fs::{File, OpenOptions};
use std::fs::File;
use std::io::BufReader;
use std::ops::DerefMut;
use std::process;

use warp::Filter;

use crate::data_model::DataStore;
use wall_disp::tasks::{Task, ToDo};

const SAVE_FILE_PATH: &str = "todo.json";

Expand Down Expand Up @@ -70,7 +69,6 @@ mod filters {
use warp::Filter;

use crate::{handlers, DataStore};
use std::hash::Hash;
use wall_disp::tasks::{Priority, Task};

pub fn task_master(
Expand All @@ -83,7 +81,7 @@ mod filters {
.or(estimate_time(storage.clone()))
.or(complete(storage.clone()))
.or(completion_status(storage.clone()))
.or(search(storage.clone())),
.or(search(storage)),
)
}

Expand Down Expand Up @@ -246,7 +244,6 @@ mod handlers {
use chrono::{DateTime, Local};
use std::ops::Deref;
use wall_disp::tasks::{CompletionStatus, EstTime, FlattenTasks, Priority, Task};
use warp::reply::Json;

pub async fn add_task(
uuid: Option<Uuid>,
Expand Down
32 changes: 14 additions & 18 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use std::collections::HashMap;

use chrono::prelude::{DateTime, Local};
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::str::FromStr;
use uuid::Uuid;

#[derive(Deserialize, Serialize, Debug)]
#[derive(Default, Deserialize, Serialize, Debug)]
pub struct ToDo {
tasks: HashMap<Uuid, Box<Task>>,
paths: HashMap<Uuid, Vec<Uuid>>,
Expand Down Expand Up @@ -66,7 +65,7 @@ impl ToDo {

let mut path_iter = path.iter();
let mut parent = self.tasks.get_mut(path_iter.next().unwrap()).unwrap();
while let Some(next_uuid) = path_iter.next() {
for next_uuid in path_iter {
parent = parent
.subtasks
.as_mut()
Expand Down Expand Up @@ -274,11 +273,11 @@ impl Task {
}

pub fn get_due_date(&self) -> Option<DateTime<Local>> {
self.due_date.clone()
self.due_date
}

pub fn get_priority(&self) -> Option<Priority> {
self.priority.clone()
self.priority
}
}

Expand All @@ -301,10 +300,10 @@ impl FlattenTasks for Task {
desc: self.desc.clone(),
finished: self.finished,
subtasks: None,
due_date: self.due_date.clone(),
_est_time: self._est_time.clone(),
priority: self.priority.clone(),
uuid: self.uuid.clone(),
due_date: self.due_date,
_est_time: self._est_time,
priority: self.priority,
uuid: self.uuid,
};
ret.push(tmp);
let subtasks = match &self.subtasks {
Expand All @@ -314,10 +313,10 @@ impl FlattenTasks for Task {
desc: task.desc.clone(),
finished: task.finished,
subtasks: None,
due_date: task.due_date.clone(),
_est_time: task._est_time.clone(),
priority: task.priority.clone(),
uuid: task.uuid.clone(),
due_date: task.due_date,
_est_time: task._est_time,
priority: task.priority,
uuid: task.uuid,
});
let children = st
.values()
Expand All @@ -335,7 +334,7 @@ impl FlattenTasks for Task {
}

impl Priority {
pub fn val(&self) -> i32 {
pub fn val(self) -> i32 {
match self {
Priority::Low => 1,
Priority::Medium => 2,
Expand Down Expand Up @@ -384,10 +383,7 @@ impl PartialEq for Task {
.all(|x| x),
None => false,
},
None => match &other.subtasks {
Some(_) => false,
None => true,
},
None => other.subtasks.is_none(),
};
subtasks_match
&& self.name == other.name
Expand Down
30 changes: 15 additions & 15 deletions src/trello_api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use chrono::prelude::{DateTime, Utc};
use reqwest::blocking::Client;
use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use serde::Deserialize as DeserializeMacro;
use serde::Serialize as SerializeMacro;
use std::env;
use std::fmt;

#[derive(Default, Clone)]
pub struct TrelloApi {
key: Option<String>,
token: Option<String>,
Expand Down Expand Up @@ -258,7 +259,7 @@ impl<'de> Deserialize<'de> for CheckItem {

fn visit_str<E>(self, value: &str) -> Result<Field, E>
where
E: de::Error,
E: Error,
{
match value {
"id" => Ok(Field::Id),
Expand Down Expand Up @@ -286,16 +287,16 @@ impl<'de> Deserialize<'de> for CheckItem {
{
let id_check_str = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
.ok_or_else(|| Error::invalid_length(0, &self))?;
let state_str: String = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(1, &self))?;
.ok_or_else(|| Error::invalid_length(1, &self))?;
let id_str = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(2, &self))?;
.ok_or_else(|| Error::invalid_length(2, &self))?;
let name_str = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(3, &self))?;
.ok_or_else(|| Error::invalid_length(3, &self))?;
Ok(CheckItem {
idChecklist: id_check_str,
id: id_str,
Expand All @@ -316,25 +317,25 @@ impl<'de> Deserialize<'de> for CheckItem {
match key {
Field::IdChecklist => {
if id_chk.is_some() {
return Err(de::Error::duplicate_field("idChecklist"));
return Err(Error::duplicate_field("idChecklist"));
}
id_chk = Some(map.next_value()?);
}
Field::State => {
if state_str.is_some() {
return Err(de::Error::duplicate_field("state"));
return Err(Error::duplicate_field("state"));
}
state_str = Some(map.next_value()?);
}
Field::Name => {
if name_str.is_some() {
return Err(de::Error::duplicate_field("name"));
return Err(Error::duplicate_field("name"));
}
name_str = Some(map.next_value()?);
}
Field::Id => {
if id_str.is_some() {
return Err(de::Error::duplicate_field("id"));
return Err(Error::duplicate_field("id"));
}
id_str = Some(map.next_value()?);
}
Expand All @@ -344,11 +345,10 @@ impl<'de> Deserialize<'de> for CheckItem {
}
}
}
let id_chk = id_chk.ok_or_else(|| de::Error::missing_field("idChecklist"))?;
let state_str: String =
state_str.ok_or_else(|| de::Error::missing_field("state"))?;
let id_str = id_str.ok_or_else(|| de::Error::missing_field("id"))?;
let name_str = name_str.ok_or_else(|| de::Error::missing_field("name"))?;
let id_chk = id_chk.ok_or_else(|| Error::missing_field("idChecklist"))?;
let state_str: String = state_str.ok_or_else(|| Error::missing_field("state"))?;
let id_str = id_str.ok_or_else(|| Error::missing_field("id"))?;
let name_str = name_str.ok_or_else(|| Error::missing_field("name"))?;
Ok(CheckItem {
idChecklist: id_chk,
id: id_str,
Expand Down

0 comments on commit d06a64d

Please sign in to comment.