Struct task_hookrs::task::Task
source · pub struct Task { /* private fields */ }Expand description
Task type
A task must have four things:
- A Status
- An UUID
- An Entry-Date
- A Description
all other Data is optional by taskwarrior. This type is a simple rust representation of the JSON exported by taskwarrior.
For further explanations of the fields please consult the documentation on https://taskwarrior.org/
It is deserializeable and serializeable via serde_json, so importing and exporting taskwarrior tasks is simply serializing and deserializing objects of this type.
Implementations§
source§impl Task
impl Task
sourcepub fn new(
id: Option<u64>,
status: TaskStatus,
uuid: Uuid,
entry: Date,
description: String,
annotations: Option<Vec<Annotation>>,
depends: Option<Vec<Uuid>>,
due: Option<Date>,
end: Option<Date>,
imask: Option<f64>,
mask: Option<String>,
modified: Option<Date>,
parent: Option<Uuid>,
priority: Option<TaskPriority>,
project: Option<Project>,
recur: Option<String>,
scheduled: Option<Date>,
start: Option<Date>,
tags: Option<Vec<Tag>>,
until: Option<Date>,
wait: Option<Date>,
urgency: Option<Urgency>,
uda: UDA
) -> Task
pub fn new(
id: Option<u64>,
status: TaskStatus,
uuid: Uuid,
entry: Date,
description: String,
annotations: Option<Vec<Annotation>>,
depends: Option<Vec<Uuid>>,
due: Option<Date>,
end: Option<Date>,
imask: Option<f64>,
mask: Option<String>,
modified: Option<Date>,
parent: Option<Uuid>,
priority: Option<TaskPriority>,
project: Option<Project>,
recur: Option<String>,
scheduled: Option<Date>,
start: Option<Date>,
tags: Option<Vec<Tag>>,
until: Option<Date>,
wait: Option<Date>,
urgency: Option<Urgency>,
uda: UDA
) -> Task
Create a new Task instance
Examples found in repository?
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
fn visit_map<V>(self, mut visitor: V) -> RResult<Task, V::Error>
where
V: MapAccess<'de>,
{
let mut id = None;
let mut status = None;
let mut uuid = None;
let mut entry = None;
let mut description = None;
let mut annotations = None;
let mut depends = None;
let mut due = None;
let mut end = None;
let mut imask = None;
let mut mask = None;
let mut modified = None;
let mut parent = None;
let mut priority = None;
let mut project = None;
let mut recur = None;
let mut scheduled = None;
let mut start = None;
let mut tags = None;
let mut until = None;
let mut wait = None;
let mut urgency = None;
let mut uda = UDA::default();
loop {
let key: Option<String> = visitor.next_key()?;
if key.is_none() {
break;
}
let key = key.unwrap();
match &key[..] {
"id" => {
id = Some(visitor.next_value()?);
}
"status" => {
status = Some(visitor.next_value()?);
}
"uuid" => {
uuid = Some(visitor.next_value()?);
}
"entry" => {
entry = Some(visitor.next_value()?);
}
"description" => {
description = Some(visitor.next_value()?);
}
"annotations" => {
annotations = Some(visitor.next_value()?);
}
"depends" => {
let raw: String = visitor.next_value()?;
let mut uuids = vec![];
for uuid in raw.split(',') {
uuids.push(Uuid::parse_str(uuid).map_err(V::Error::custom)?);
}
depends = Some(uuids);
}
"due" => {
due = Some(visitor.next_value()?);
}
"end" => {
end = Some(visitor.next_value()?);
}
"imask" => {
imask = Some(visitor.next_value()?);
}
"mask" => {
mask = Some(visitor.next_value()?);
}
"modified" => {
modified = Some(visitor.next_value()?);
}
"parent" => {
parent = Some(visitor.next_value()?);
}
"priority" => {
priority = Some(visitor.next_value()?);
}
"project" => {
project = Some(visitor.next_value()?);
}
"recur" => {
recur = Some(visitor.next_value()?);
}
"scheduled" => {
scheduled = Some(visitor.next_value()?);
}
"start" => {
start = Some(visitor.next_value()?);
}
"tags" => {
tags = Some(visitor.next_value()?);
}
"until" => {
until = Some(visitor.next_value()?);
}
"wait" => {
wait = Some(visitor.next_value()?);
}
"urgency" => {
urgency = Some(visitor.next_value()?);
}
field => {
log::debug!("Inserting '{}' as UDA", field);
let uda_value: UDAValue = visitor.next_value()?;
uda.insert(UDAName::from(field), uda_value);
}
}
}
let status = status.ok_or_else(|| V::Error::missing_field("status"))?;
let uuid = uuid.ok_or_else(|| V::Error::missing_field("uuid"))?;
let entry = entry.ok_or_else(|| V::Error::missing_field("entry"))?;
let description = description.ok_or_else(|| V::Error::missing_field("description"))?;
let task = Task::new(
id,
status,
uuid,
entry,
description,
annotations,
depends,
due,
end,
imask,
mask,
modified,
parent,
priority,
project,
recur,
scheduled,
start,
tags,
until,
wait,
urgency,
uda,
);
Ok(task)
}sourcepub fn status(&self) -> &TaskStatus
pub fn status(&self) -> &TaskStatus
Get the status of the task
sourcepub fn status_mut(&mut self) -> &mut TaskStatus
pub fn status_mut(&mut self) -> &mut TaskStatus
Get the status of the task mutable
sourcepub fn description(&self) -> &String
pub fn description(&self) -> &String
Get the description of the task
sourcepub fn description_mut(&mut self) -> &mut String
pub fn description_mut(&mut self) -> &mut String
Get the description of the task mutable
sourcepub fn annotations(&self) -> Option<&Vec<Annotation>>
pub fn annotations(&self) -> Option<&Vec<Annotation>>
Get the annotations of the task
sourcepub fn annotations_mut(&mut self) -> Option<&mut Vec<Annotation>>
pub fn annotations_mut(&mut self) -> Option<&mut Vec<Annotation>>
Get the annotations of the task mutable
sourcepub fn set_annotations<T, A>(&mut self, new: Option<T>)where
T: IntoIterator,
T::Item: Into<Annotation>,
pub fn set_annotations<T, A>(&mut self, new: Option<T>)where
T: IntoIterator,
T::Item: Into<Annotation>,
Set annotations
sourcepub fn depends_mut(&mut self) -> Option<&mut Vec<Uuid>>
pub fn depends_mut(&mut self) -> Option<&mut Vec<Uuid>>
Get the dependencies of the task mutable
sourcepub fn set_depends<T, U>(&mut self, new: Option<T>)where
T: IntoIterator,
T::Item: Into<Uuid>,
pub fn set_depends<T, U>(&mut self, new: Option<T>)where
T: IntoIterator,
T::Item: Into<Uuid>,
Set depends
sourcepub fn modified_mut(&mut self) -> Option<&mut Date>
pub fn modified_mut(&mut self) -> Option<&mut Date>
Get the modified date of the task mutable
sourcepub fn set_modified<T>(&mut self, new: Option<T>)where
T: Into<Date>,
pub fn set_modified<T>(&mut self, new: Option<T>)where
T: Into<Date>,
Set modified
sourcepub fn parent_mut(&mut self) -> Option<&mut Uuid>
pub fn parent_mut(&mut self) -> Option<&mut Uuid>
Get the parent of the task mutable
sourcepub fn set_parent<T>(&mut self, new: Option<T>)where
T: Into<Uuid>,
pub fn set_parent<T>(&mut self, new: Option<T>)where
T: Into<Uuid>,
Set parent
sourcepub fn priority(&self) -> Option<&TaskPriority>
pub fn priority(&self) -> Option<&TaskPriority>
Get the priority of the task
sourcepub fn priority_mut(&mut self) -> Option<&mut TaskPriority>
pub fn priority_mut(&mut self) -> Option<&mut TaskPriority>
Get the priority of the task mutable
sourcepub fn set_priority<T>(&mut self, new: Option<T>)where
T: Into<TaskPriority>,
pub fn set_priority<T>(&mut self, new: Option<T>)where
T: Into<TaskPriority>,
Set priority
sourcepub fn project_mut(&mut self) -> Option<&mut Project>
pub fn project_mut(&mut self) -> Option<&mut Project>
Get the project of the task mutable
sourcepub fn set_project<T>(&mut self, new: Option<T>)where
T: Into<Project>,
pub fn set_project<T>(&mut self, new: Option<T>)where
T: Into<Project>,
Set project
sourcepub fn recur(&self) -> Option<&String>
pub fn recur(&self) -> Option<&String>
Get the recur of the task
This is exported as String by now. This might change in future versions of this crate.
sourcepub fn recur_mut(&mut self) -> Option<&mut String>
pub fn recur_mut(&mut self) -> Option<&mut String>
This is exported as String by now. This might change in future versions of this crate. mutable
sourcepub fn scheduled_mut(&mut self) -> Option<&mut Date>
pub fn scheduled_mut(&mut self) -> Option<&mut Date>
Get the scheduled date of the task mutable
sourcepub fn set_scheduled<T>(&mut self, new: Option<T>)where
T: Into<Date>,
pub fn set_scheduled<T>(&mut self, new: Option<T>)where
T: Into<Date>,
Set scheduled
Get the tags of the task
Get the tags of the task mutable
Set tags
sourcepub fn urgency_mut(&mut self) -> Option<&mut Urgency>
pub fn urgency_mut(&mut self) -> Option<&mut Urgency>
Get the urgency of the task
sourcepub fn set_urgency<T>(&mut self, new: Option<T>)where
T: Into<Urgency>,
pub fn set_urgency<T>(&mut self, new: Option<T>)where
T: Into<Urgency>,
Set the urgency of the task
sourcepub fn uda(&self) -> &UDA
pub fn uda(&self) -> &UDA
Get the BTreeMap that contains the UDA
Examples found in repository?
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
fn serialize<S>(&self, serializer: S) -> RResult<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_map(None)?;
state.serialize_entry("status", &self.status)?;
state.serialize_entry("uuid", &self.uuid)?;
state.serialize_entry("entry", &self.entry)?;
state.serialize_entry("description", &self.description)?;
self.annotations
.as_ref()
.map(|v| state.serialize_entry("annotations", v));
self.tags.as_ref().map(|v| state.serialize_entry("tags", v));
self.id.as_ref().map(|v| state.serialize_entry("id", v));
self.recur
.as_ref()
.map(|ref v| state.serialize_entry("recur", v));
self.depends.as_ref().map(|v| {
let v: Vec<String> = v.iter().map(Uuid::to_string).collect();
state.serialize_entry("depends", &v.join(","))
});
self.due
.as_ref()
.map(|ref v| state.serialize_entry("due", v));
self.end
.as_ref()
.map(|ref v| state.serialize_entry("end", v));
self.imask
.as_ref()
.map(|ref v| state.serialize_entry("imask", v));
self.mask
.as_ref()
.map(|ref v| state.serialize_entry("mask", v));
self.modified
.as_ref()
.map(|ref v| state.serialize_entry("modified", v));
self.parent
.as_ref()
.map(|ref v| state.serialize_entry("parent", v));
self.priority
.as_ref()
.map(|ref v| state.serialize_entry("priority", v));
self.project
.as_ref()
.map(|ref v| state.serialize_entry("project", v));
self.scheduled
.as_ref()
.map(|ref v| state.serialize_entry("scheduled", v));
self.start
.as_ref()
.map(|ref v| state.serialize_entry("start", v));
self.until
.as_ref()
.map(|ref v| state.serialize_entry("until", v));
self.wait
.as_ref()
.map(|ref v| state.serialize_entry("wait", v));
self.urgency
.as_ref()
.map(|ref v| state.serialize_entry("urgency", v));
for (key, value) in self.uda().iter() {
state.serialize_entry(key, value)?;
}
state.end()
}