Skip to content

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
imran-iq committed Oct 12, 2021
1 parent 392c332 commit cb407f1
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 117 deletions.
4 changes: 2 additions & 2 deletions examples/create_task.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate task_hookrs;
extern crate chrono;
extern crate serde_json;
extern crate task_hookrs;
extern crate uuid;

use task_hookrs::task::Task;
use task_hookrs::status::TaskStatus;
use task_hookrs::task::Task;
use task_hookrs::uda::UDA;

use chrono::NaiveDateTime;
Expand Down
4 changes: 2 additions & 2 deletions examples/import_task.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate task_hookrs;
extern crate chrono;
extern crate serde_json;
extern crate task_hookrs;
extern crate uuid;

use std::io::stdin;

use task_hookrs::status::TaskStatus;
use task_hookrs::import::import;
use task_hookrs::status::TaskStatus;

fn main() {
let mut tasks = import(stdin()).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use std::ops::{Deref, DerefMut};

use serde::Serialize;
use serde::Serializer;
use chrono::NaiveDateTime;
use serde::de::Error as SerdeError;
use serde::de::Visitor;
use serde::Deserialize;
use serde::Deserializer;
use serde::de::Visitor;
use serde::de::Error as SerdeError;
use chrono::NaiveDateTime;
use serde::Serialize;
use serde::Serializer;

/// Date is a NaiveDateTime-Wrapper object to be able to implement foreign traits on it
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
Expand Down
4 changes: 1 addition & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/// Failure error kind type, defining error messages
#[derive(Debug, Clone, Eq, PartialEq, Fail)]
pub enum ErrorKind {

/// Error kind indicating that the JSON parser failed
#[fail(display = "Failed to create a Task from JSON")]
ParserError,
Expand All @@ -24,6 +23,5 @@ pub enum ErrorKind {

/// Error kind indicating that a conversion to JSON failed
#[fail(display = "A Task could not be converted to JSON")]
SerializeError
SerializeError,
}

30 changes: 18 additions & 12 deletions src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,39 @@
use std::io::BufRead;
use std::io::Read;

use serde_json;
use failure::Error;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
use serde_json;

use task::Task;
use error::ErrorKind as EK;
use task::Task;

/// Import taskwarrior-exported JSON. This expects an JSON Array of objects, as exported by
/// taskwarrior.
pub fn import<R: Read>(r: R) -> Result<Vec<Task>> {
serde_json::from_reader(r).context(EK::ParserError).map_err(Error::from)
serde_json::from_reader(r)
.context(EK::ParserError)
.map_err(Error::from)
}

/// Import a single JSON-formatted Task
pub fn import_task(s: &str) -> Result<Task> {
serde_json::from_str(s).context(EK::ParserError).map_err(Error::from)
serde_json::from_str(s)
.context(EK::ParserError)
.map_err(Error::from)
}

/// Reads line by line and tries to parse a task-object per line.
pub fn import_tasks<BR: BufRead>(r: BR) -> Vec<Result<Task>> {
let mut vt = Vec::new();
for line in r.lines() {
if line.is_err() {
vt.push(Err(line.unwrap_err()).context(EK::ReaderError).map_err(Error::from));
vt.push(
Err(line.unwrap_err())
.context(EK::ReaderError)
.map_err(Error::from),
);
continue;
}
// Unwrap is safe because of continue above
Expand Down Expand Up @@ -127,11 +135,11 @@ fn test_two() {

#[test]
fn test_one_single() {
use status::TaskStatus;
use chrono::NaiveDateTime;
use date::Date;
use date::TASKWARRIOR_DATETIME_TEMPLATE;
use status::TaskStatus;
use uuid::Uuid;
use chrono::NaiveDateTime;
fn mkdate(s: &str) -> Date {
let n = NaiveDateTime::parse_from_str(s, TASKWARRIOR_DATETIME_TEMPLATE);
Date::from(n.unwrap())
Expand Down Expand Up @@ -165,9 +173,7 @@ fn test_one_single() {
assert!(task.project() == Some(&String::from("someproject")));
if let Some(tags) = task.tags() {
for tag in tags {
let any_tag = ["some", "tags", "are", "here"].iter().any(
|t| tag == *t,
);
let any_tag = ["some", "tags", "are", "here"].iter().any(|t| tag == *t);
assert!(any_tag, "Tag {} missing", tag);
}
} else {
Expand All @@ -179,8 +185,8 @@ fn test_one_single() {

#[test]
fn test_two_single() {
use std::io::BufReader;
use status::TaskStatus;
use std::io::BufReader;
let s = r#"
{"id":1,"description":"some description","entry":"20150619T165438Z","modified":"20160327T164007Z","project":"someproject","status":"waiting","tags":["some","tags","are","here"],"uuid":"8ca953d5-18b4-4eb9-bd56-18f2e5b752f0","wait":"20160508T164007Z","urgency":0.583562}
{"id":1,"description":"some description","entry":"20150619T165438Z","modified":"20160327T164007Z","project":"someproject","status":"waiting","tags":["some","tags","are","here"],"uuid":"8ca953d5-18b4-4eb9-bd56-18f2e5b752f0","wait":"20160508T164007Z","urgency":0.583562}"#;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
unused_must_use,
unused_mut,
unused_qualifications,
while_true,
while_true
)]

extern crate chrono;
Expand Down Expand Up @@ -69,6 +69,6 @@ pub mod project;
pub mod status;
pub mod tag;
pub mod task;
pub mod tw;
pub mod uda;
pub mod urgency;
pub mod tw;
2 changes: 1 addition & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

//! Module containing `TaskStatus` type and trait impls
use std::fmt::{Display, Formatter, Error as FmtError};
use std::fmt::{Display, Error as FmtError, Formatter};

/// Enum for status taskwarrior supports.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit cb407f1

Please sign in to comment.