summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-09-30 20:55:02 +0200
committerGitHub <noreply@github.com>2018-09-30 20:55:02 +0200
commit34b680ef03423d6b9daaf1ae80321fac5dd1535b (patch)
treeaf0cea040ba46cf6c81165e164f043cf90a104fa
parentfe2871fd8ace5b2d9b010eeac0881440cd11b358 (diff)
parent53ec0a5a99316877f39c9897eff039d7316bd794 (diff)
Merge pull request #73 from maralorn/fix-mutability
Add setters
-rw-r--r--src/task.rs132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/task.rs b/src/task.rs
index 7d059c1..fbfffff 100644
--- a/src/task.rs
+++ b/src/task.rs
@@ -227,6 +227,15 @@ impl Task {
self.annotations.as_mut()
}
+ /// Set annotations
+ pub fn set_annotations<T, A>(&mut self, new: Option<T>)
+ where
+ T: IntoIterator,
+ T::Item: Into<Annotation>,
+ {
+ self.annotations = new.map(|x| x.into_iter().map(Into::into).collect());
+ }
+
/// Get the dependencies of the task
pub fn depends(&self) -> Option<&Vec<Uuid>> {
self.depends.as_ref()
@@ -237,6 +246,15 @@ impl Task {
self.depends.as_mut()
}
+ /// Set depends
+ pub fn set_depends<T, U>(&mut self, new: Option<T>)
+ where
+ T: IntoIterator,
+ T::Item: Into<Uuid>,
+ {
+ self.depends = new.map(|x| x.into_iter().map(Into::into).collect());
+ }
+
/// Get the due date of the task
pub fn due(&self) -> Option<&Date> {
self.due.as_ref()
@@ -247,6 +265,14 @@ impl Task {
self.due.as_mut()
}
+ /// Set due
+ pub fn set_due<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.due = new.map(Into::into)
+ }
+
/// Get the end date of the task
pub fn end(&self) -> Option<&Date> {
self.end.as_ref()
@@ -257,6 +283,14 @@ impl Task {
self.end.as_mut()
}
+ /// Set end
+ pub fn set_end<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.end = new.map(Into::into)
+ }
+
/// Get the imask of the task
pub fn imask(&self) -> Option<&i64> {
self.imask.as_ref()
@@ -267,6 +301,14 @@ impl Task {
self.imask.as_mut()
}
+ /// Set imask
+ pub fn set_imask<T>(&mut self, new: Option<T>)
+ where
+ T: Into<i64>,
+ {
+ self.imask = new.map(Into::into)
+ }
+
/// Get the mask of the task
pub fn mask(&self) -> Option<&String> {
self.mask.as_ref()
@@ -277,6 +319,14 @@ impl Task {
self.mask.as_mut()
}
+ /// Set mask
+ pub fn set_mask<T>(&mut self, new: Option<T>)
+ where
+ T: Into<String>,
+ {
+ self.mask = new.map(Into::into)
+ }
+
/// Get the modified date of the task
pub fn modified(&self) -> Option<&Date> {
self.modified.as_ref()
@@ -287,6 +337,14 @@ impl Task {
self.modified.as_mut()
}
+ /// Set modified
+ pub fn set_modified<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.modified = new.map(Into::into)
+ }
+
/// Get the parent of the task
pub fn parent(&self) -> Option<&Uuid> {
self.parent.as_ref()
@@ -297,6 +355,14 @@ impl Task {
self.parent.as_mut()
}
+ /// Set parent
+ pub fn set_parent<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Uuid>,
+ {
+ self.parent = new.map(Into::into)
+ }
+
/// Get the priority of the task
pub fn priority(&self) -> Option<&TaskPriority> {
self.priority.as_ref()
@@ -307,6 +373,14 @@ impl Task {
self.priority.as_mut()
}
+ /// Set priority
+ pub fn set_priority<T>(&mut self, new: Option<T>)
+ where
+ T: Into<TaskPriority>,
+ {
+ self.priority = new.map(Into::into)
+ }
+
/// Get the project of the task
pub fn project(&self) -> Option<&Project> {
self.project.as_ref()
@@ -317,6 +391,14 @@ impl Task {
self.project.as_mut()
}
+ /// Set project
+ pub fn set_project<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Project>,
+ {
+ self.project = new.map(Into::into)
+ }
+
/// Get the recur of the task
///
/// This is exported as String by now. This might change in future versions of this crate.
@@ -330,6 +412,14 @@ impl Task {
self.recur.as_mut()
}
+ /// Set recur
+ pub fn set_recur<T>(&mut self, new: Option<T>)
+ where
+ T: Into<String>,
+ {
+ self.recur = new.map(Into::into)
+ }
+
/// Get the scheduled date of the task
pub fn scheduled(&self) -> Option<&Date> {
self.scheduled.as_ref()
@@ -340,6 +430,14 @@ impl Task {
self.scheduled.as_mut()
}
+ /// Set scheduled
+ pub fn set_scheduled<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.scheduled = new.map(Into::into)
+ }
+
/// Get the start date of the task
pub fn start(&self) -> Option<&Date> {
self.start.as_ref()
@@ -350,6 +448,14 @@ impl Task {
self.start.as_mut()
}
+ /// Set start
+ pub fn set_start<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.start = new.map(Into::into)
+ }
+
/// Get the tags of the task
pub fn tags(&self) -> Option<&Vec<Tag>> {
self.tags.as_ref()
@@ -360,6 +466,15 @@ impl Task {
self.tags.as_mut()
}
+ /// Set tags
+ pub fn set_tags<T, K>(&mut self, new: Option<T>)
+ where
+ T: IntoIterator,
+ T::Item: Into<Tag>,
+ {
+ self.tags = new.map(|x| x.into_iter().map(Into::into).collect());
+ }
+
/// Get the until date of the task
pub fn until(&self) -> Option<&Date> {
self.until.as_ref()
@@ -370,6 +485,14 @@ impl Task {
self.until.as_mut()
}
+ /// Set until
+ pub fn set_until<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.until = new.map(Into::into);
+ }
+
/// Get the wait date of the task
pub fn wait(&self) -> Option<&Date> {
self.wait.as_ref()
@@ -379,6 +502,15 @@ impl Task {
pub fn wait_mut(&mut self) -> Option<&mut Date> {
self.wait.as_mut()
}
+
+ /// Set wait
+ pub fn set_wait<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Date>,
+ {
+ self.wait = new.map(Into::into);
+ }
+
/// Get the BTreeMap that contains the UDA
pub fn uda(&self) -> &UDA {
&self.uda