Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zmbush committed Sep 26, 2019
1 parent 4f1ed3e commit 152e9ec
Show file tree
Hide file tree
Showing 30 changed files with 300 additions and 240 deletions.
7 changes: 6 additions & 1 deletion bin/rustup
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/bash

rustup override set 1.31.0
rustup override set 1.37.0
rustup component add clippy
rustup component add rust-src
rustup component add rustfmt
rustup component add rls
rustup component add rust-analysis
7 changes: 3 additions & 4 deletions budgetronlib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ use std::io::Read;
use std::path::PathBuf;
use toml;


#[derive(Deserialize)]
pub struct EmailAccount {
pub username: String,
pub password: String,
pub server: String,
pub port: u16,
pub server: String,
pub port: u16,
}

#[derive(Deserialize)]
pub struct SecureConfig {}

#[derive(Deserialize, Debug)]
pub struct CategoryConfig {
pub categories: HashMap<String, Vec<String>>,
pub categories: HashMap<String, Vec<String>>,
pub ignored_accounts: Vec<String>,
}

Expand Down
31 changes: 18 additions & 13 deletions budgetronlib/src/fintime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

use self::Timeframe::*;
use chrono;
use chrono::Datelike;
use chrono::offset::TimeZone;
use chrono::Datelike;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::ops;
Expand Down Expand Up @@ -126,19 +126,23 @@ impl Date {
}

pub fn uid(&self) -> String {
format!("{:04}{:02}{:02}",
self.date.year(),
self.date.month(),
self.date.day())
format!(
"{:04}{:02}{:02}",
self.date.year(),
self.date.month(),
self.date.day()
)
}

fn move_days(&mut self, days: i64) {
self.date = self.date + chrono::Duration::days(days);
}

fn move_one_month(&mut self, forward: bool) {
let days = days_in_month(i64::from(self.date.month()) - if forward { 0 } else { 1 },
i64::from(self.date.year()));
let days = days_in_month(
i64::from(self.date.month()) - if forward { 0 } else { 1 },
i64::from(self.date.year()),
);
self.move_days(days * if forward { 1 } else { -1 });
}

Expand All @@ -165,7 +169,6 @@ impl Date {
*self -= Days(days);
}


pub fn align_to_quarter(&mut self) {
self.align_to_month();
let months = i64::from(self.date.month0()) % 3;
Expand All @@ -187,7 +190,9 @@ impl Date {
}

pub fn ymd(y: i32, m: i32, d: i32) -> Date {
Date { date: chrono::Utc.ymd(y, m as u32, d as u32) }
Date {
date: chrono::Utc.ymd(y, m as u32, d as u32),
}
}

pub fn year(&self) -> i32 {
Expand Down Expand Up @@ -220,7 +225,7 @@ macro_rules! forward_ref_binop {
ops::$imp::$method(*self, *other)
}
}
}
};
}

impl ops::Sub<Timeframe> for Date {
Expand Down Expand Up @@ -308,11 +313,11 @@ impl<'de> de::Visitor<'de> for DateVisitor {
match $d.next() {
Some(s) => match s.parse() {
Ok(i) => i,
Err(_) => return error
Err(_) => return error,
},
None => return error
None => return error,
}
}
};
}

let val = if value.contains(' ') {
Expand Down
2 changes: 1 addition & 1 deletion budgetronlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ extern crate serde;
extern crate serde_derive;
extern crate toml;

pub mod fintime;
pub mod config;
pub mod error;
pub mod fintime;
2 changes: 1 addition & 1 deletion data_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#[macro_use]
extern crate diesel_codegen;

pub mod schema;
pub mod models;
pub mod schema;

extern crate chrono;
#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
match_block_trailing_comma = true
struct_field_align_threshold = 20
use_field_init_shorthand = true
use_try_shorthand = true
1 change: 0 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub enum Error {

pub type Result<T> = ::std::result::Result<T, Error>;


impl From<io::Error> for Error {
fn from(e: io::Error) -> Error {
Error::IO(e)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_json;

pub mod error;
pub mod loading;
pub mod processing;
pub mod reporting;
pub mod error;
30 changes: 15 additions & 15 deletions src/loading/alliant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ pub struct AlliantExport {
impl Genericize for AlliantExport {
fn genericize(self) -> BResult<Transaction> {
Ok(Transaction {
uid: Some(self.id),
date: self.posted_at,
person: "".to_owned(),
description: self.nickname,
original_description: self.original_name,
amount: self.amount,
transaction_type: self.transaction_type.into(),
category: self.tags.clone(),
original_category: self.tags,
account_name: self.account_name,
labels: "".to_owned(),
notes: "".to_owned(),
transfer_destination_account: None,
tags: vec![],
})
uid: Some(self.id),
date: self.posted_at,
person: "".to_owned(),
description: self.nickname,
original_description: self.original_name,
amount: self.amount,
transaction_type: self.transaction_type.into(),
category: self.tags.clone(),
original_category: self.tags,
account_name: self.account_name,
labels: "".to_owned(),
notes: "".to_owned(),
transfer_destination_account: None,
tags: vec![],
})
}
}
2 changes: 1 addition & 1 deletion src/loading/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// except according to those terms.

use budgetronlib::error::BResult;
use loading::money::Money;
use budgetronlib::fintime::Date;
use loading::money::Money;

#[derive(Debug, Serialize, Copy, Deserialize, PartialEq, Clone, Eq, PartialOrd, Ord)]
pub enum TransactionType {
Expand Down
38 changes: 19 additions & 19 deletions src/loading/logix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ pub struct LogixExport {
impl Genericize for LogixExport {
fn genericize(self) -> BResult<Transaction> {
Ok(Transaction {
uid: None,
date: self.date,
person: "".to_owned(),
description: self.description.clone(),
original_description: self.description,
amount: self.amount.abs(),
transaction_type: if self.amount.is_negative() {
TransactionType::Debit
} else {
TransactionType::Credit
},
category: self.category.clone(),
original_category: self.category,
account_name: self.account,
labels: self.memo,
notes: self.notes,
transfer_destination_account: None,
tags: vec![],
})
uid: None,
date: self.date,
person: "".to_owned(),
description: self.description.clone(),
original_description: self.description,
amount: self.amount.abs(),
transaction_type: if self.amount.is_negative() {
TransactionType::Debit
} else {
TransactionType::Credit
},
category: self.category.clone(),
original_category: self.category,
account_name: self.account,
labels: self.memo,
notes: self.notes,
transfer_destination_account: None,
tags: vec![],
})
}
}
30 changes: 15 additions & 15 deletions src/loading/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ pub struct MintExport {
impl Genericize for MintExport {
fn genericize(self) -> BResult<Transaction> {
Ok(Transaction {
uid: None,
date: self.date,
person: "".to_owned(),
description: self.description,
original_description: self.original_description,
amount: self.amount,
transaction_type: self.transaction_type.into(),
category: self.category.clone(),
original_category: self.category,
account_name: self.account_name,
labels: self.labels,
notes: self.notes,
transfer_destination_account: None,
tags: vec![],
})
uid: None,
date: self.date,
person: "".to_owned(),
description: self.description,
original_description: self.original_description,
amount: self.amount,
transaction_type: self.transaction_type.into(),
category: self.category.clone(),
original_category: self.category,
account_name: self.account_name,
labels: self.labels,
notes: self.notes,
transfer_destination_account: None,
tags: vec![],
})
}
}
6 changes: 3 additions & 3 deletions src/loading/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub mod alliant;
mod generic;
pub mod logix;
pub mod mint;
pub mod alliant;
mod util;
mod money;
mod util;

pub use self::generic::{Transaction, TransactionType};
pub use self::util::load_from_files;
pub use self::money::Money;
pub use self::util::load_from_files;
46 changes: 24 additions & 22 deletions src/loading/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ where
}

struct StdinSource<'a> {
buf: Vec<u8>,
loc: usize,
buf: Vec<u8>,
loc: usize,
stdin: StdinLock<'a>,
}

impl<'a> StdinSource<'a> {
fn new(stdin: &'a Stdin) -> StdinSource<'a> {
StdinSource {
buf: Vec::new(),
loc: 0,
buf: Vec::new(),
loc: 0,
stdin: stdin.lock(),
}
}
Expand All @@ -62,7 +62,7 @@ impl<'a> Seek for Source<'a> {
io::SeekFrom::Start(loc) => {
source.loc = loc as usize;
Ok(source.loc as u64)
},
}
io::SeekFrom::Current(diff) => {
if diff >= 0 {
source.loc += diff as usize;
Expand All @@ -77,7 +77,7 @@ impl<'a> Seek for Source<'a> {
} else {
Ok(source.loc as u64)
}
},
}
io::SeekFrom::End(_) => Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Stdin has no end",
Expand All @@ -91,24 +91,26 @@ impl<'a> Read for Source<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match *self {
Source::File(ref mut f) => f.read(buf),
Source::Stdin(ref mut source) => if source.loc >= source.buf.len() {
let ret = source.stdin.read(buf);
if let Ok(size) = ret {
source.buf.extend_from_slice(&buf[..size]);
source.loc += size;
Ok(size)
Source::Stdin(ref mut source) => {
if source.loc >= source.buf.len() {
let ret = source.stdin.read(buf);
if let Ok(size) = ret {
source.buf.extend_from_slice(&buf[..size]);
source.loc += size;
Ok(size)
} else {
ret
}
} else {
ret
let len = buf.len();
let start = source.loc;
let end = min(start + len, source.buf.len());
let readlen = end - start;
buf[..readlen].copy_from_slice(&source.buf[start..end]);
source.loc = end;
Ok(readlen)
}
} else {
let len = buf.len();
let start = source.loc;
let end = min(start + len, source.buf.len());
let readlen = end - start;
buf[..readlen].copy_from_slice(&source.buf[start..end]);
source.loc = end;
Ok(readlen)
},
}
}
}
}
Expand Down
Loading

0 comments on commit 152e9ec

Please sign in to comment.