Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an ordered map for serialization #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/habit/bit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::default::Default;

use chrono::NaiveDate;
Expand Down Expand Up @@ -37,7 +37,7 @@ impl From<bool> for CustomBool {
#[derive(Debug, Serialize, Deserialize)]
pub struct Bit {
name: String,
stats: HashMap<NaiveDate, CustomBool>,
stats: BTreeMap<NaiveDate, CustomBool>,
goal: CustomBool,

#[serde(default = "default_auto")]
Expand All @@ -51,7 +51,7 @@ impl Bit {
pub fn new(name: impl AsRef<str>, auto: bool) -> Self {
return Bit {
name: name.as_ref().to_owned(),
stats: HashMap::new(),
stats: BTreeMap::new(),
goal: CustomBool(true),
auto,
inner_data: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions src/habit/count.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::default::Default;

use chrono::NaiveDate;
Expand All @@ -12,7 +12,7 @@ use crate::habit::{InnerData, TrackEvent};
#[derive(Debug, Serialize, Deserialize)]
pub struct Count {
name: String,
stats: HashMap<NaiveDate, u32>,
stats: BTreeMap<NaiveDate, u32>,
goal: u32,

#[serde(default = "default_auto")]
Expand All @@ -26,7 +26,7 @@ impl Count {
pub fn new(name: impl AsRef<str>, goal: u32, auto: bool) -> Self {
return Count {
name: name.as_ref().to_owned(),
stats: HashMap::new(),
stats: BTreeMap::new(),
goal,
auto,
inner_data: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions src/habit/float.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::{Eq, Ord, PartialEq};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::default::Default;
use std::fmt;
use std::ops::{Add, Sub};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Sub for FloatData {
#[derive(Debug, Serialize, Deserialize)]
pub struct Float {
name: String,
stats: HashMap<NaiveDate, FloatData>,
stats: BTreeMap<NaiveDate, FloatData>,
goal: FloatData,
precision: u8,
#[serde(default = "default_auto")]
Expand All @@ -94,7 +94,7 @@ impl Float {
pub fn new(name: impl AsRef<str>, goal: u32, precision: u8, auto: bool) -> Self {
return Float {
name: name.as_ref().to_owned(),
stats: HashMap::new(),
stats: BTreeMap::new(),
goal: FloatData {
value: goal,
precision,
Expand Down