Verified Commit e6ac775f authored by Maxime Buquet's avatar Maxime Buquet
Browse files

Expose ChronophageDays publicly


Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent 7818e0da
......@@ -180,29 +180,31 @@ impl Day {
// TODO: This is a really poor attempt at being able to Serialize Day and
// Vec<Day> the same way. There must be a better way. Halp.
#[derive(Debug, Clone, PartialEq)]
pub struct Days (Vec<Day>);
pub struct Days {
pub days: Vec<Day>
}
impl Days {
pub fn new(days: Vec<Day>) -> Days {
Days (days)
Days { days }
}
}
impl From<Day> for Days {
fn from(day: Day) -> Days {
Days(vec![day])
Days { days: vec![day] }
}
}
impl From<Vec<Day>> for Days {
fn from(vec: Vec<Day>) -> Days {
Days(vec)
Days { days: vec }
}
}
impl Into<Vec<Day>> for Days {
fn into(self: Days) -> Vec<Day> {
self.0
self.days
}
}
......@@ -211,8 +213,8 @@ impl Serialize for Days {
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.0.len()))?;
self.0.iter().try_for_each(|day| -> Result<(), S::Error> {
let mut map = serializer.serialize_map(Some(self.days.len()))?;
self.days.iter().try_for_each(|day| -> Result<(), S::Error> {
let s_date = day.date.format("%Y-%m-%d").to_string();
let s_items = day.items.iter().fold(String::new(), |mut s, item| {
s.push_str(String::from(item).as_str());
......
......@@ -10,7 +10,7 @@ pub mod timelog;
pub mod timesheet;
pub use self::chronophage::{
Day as ChronophageDay, Entry as ChronophageEntry, Task as ChronophageTask,
Day as ChronophageDay, Days as ChronophageDays, Entry as ChronophageEntry, Task as ChronophageTask,
};
pub use self::task::Task;
pub use self::timelog::{EntryType, TimelogDay, TimelogEntry};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment