pub struct Task { /* private fields */ }Expand description
A to-do task
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(name: String, completed: bool, parent_calendar_url: &Url) -> Self
pub fn new(name: String, completed: bool, parent_calendar_url: &Url) -> Self
Create a brand new Task that is not on a server yet. This will pick a new (random) task ID.
Examples found in repository?
examples/provider-sync.rs (line 58)
43async fn add_items_and_sync_again(provider: &mut CalDavProvider) {
44 println!("\nNow, we'll add a calendar and a few tasks and run the sync again.");
45 pause();
46
47 // Create a new calendar...
48 let new_calendar_url: Url = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
49 let new_calendar_name = "A brave new calendar".to_string();
50 if let Err(_err) = provider.local_mut()
51 .create_calendar(new_calendar_url.clone(), new_calendar_name.clone(), SupportedComponents::TODO, Some("#ff8000".parse().unwrap()))
52 .await {
53 println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
54 }
55
56 // ...and add a task in it
57 let new_name = "This is a new task in a new calendar";
58 let new_task = Task::new(String::from(new_name), true, &new_calendar_url);
59 provider.local().get_calendar(&new_calendar_url).await.unwrap()
60 .lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
61
62
63 // Also create a task in a previously existing calendar
64 let changed_calendar_url: Url = EXAMPLE_EXISTING_CALENDAR_URL.parse().unwrap();
65 let new_task_name = "This is a new task we're adding as an example, with ÜTF-8 characters";
66 let new_task = Task::new(String::from(new_task_name), false, &changed_calendar_url);
67 let new_url = new_task.url().clone();
68 provider.local().get_calendar(&changed_calendar_url).await.unwrap()
69 .lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
70
71
72 if provider.sync().await == false {
73 log::warn!("Sync did not complete, see the previous log lines for more info. You can safely start a new sync. The new task may not have been synced.");
74 } else {
75 println!("Done syncing the new task '{}' and the new calendar '{}'", new_task_name, new_calendar_name);
76 }
77 provider.local().save_to_folder().unwrap();
78
79 complete_item_and_sync_again(provider, &changed_calendar_url, &new_url).await;
80}Sourcepub fn new_with_parameters(
name: String,
uid: String,
new_url: Url,
completion_status: CompletionStatus,
sync_status: SyncStatus,
creation_date: Option<DateTime<Utc>>,
last_modified: DateTime<Utc>,
ical_prod_id: String,
extra_parameters: Vec<Property>,
) -> Self
pub fn new_with_parameters( name: String, uid: String, new_url: Url, completion_status: CompletionStatus, sync_status: SyncStatus, creation_date: Option<DateTime<Utc>>, last_modified: DateTime<Utc>, ical_prod_id: String, extra_parameters: Vec<Property>, ) -> Self
Create a new Task instance, that may be synced on the server already
Sourcepub fn url(&self) -> &Url
pub fn url(&self) -> &Url
Examples found in repository?
examples/provider-sync.rs (line 67)
43async fn add_items_and_sync_again(provider: &mut CalDavProvider) {
44 println!("\nNow, we'll add a calendar and a few tasks and run the sync again.");
45 pause();
46
47 // Create a new calendar...
48 let new_calendar_url: Url = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
49 let new_calendar_name = "A brave new calendar".to_string();
50 if let Err(_err) = provider.local_mut()
51 .create_calendar(new_calendar_url.clone(), new_calendar_name.clone(), SupportedComponents::TODO, Some("#ff8000".parse().unwrap()))
52 .await {
53 println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
54 }
55
56 // ...and add a task in it
57 let new_name = "This is a new task in a new calendar";
58 let new_task = Task::new(String::from(new_name), true, &new_calendar_url);
59 provider.local().get_calendar(&new_calendar_url).await.unwrap()
60 .lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
61
62
63 // Also create a task in a previously existing calendar
64 let changed_calendar_url: Url = EXAMPLE_EXISTING_CALENDAR_URL.parse().unwrap();
65 let new_task_name = "This is a new task we're adding as an example, with ÜTF-8 characters";
66 let new_task = Task::new(String::from(new_task_name), false, &changed_calendar_url);
67 let new_url = new_task.url().clone();
68 provider.local().get_calendar(&changed_calendar_url).await.unwrap()
69 .lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
70
71
72 if provider.sync().await == false {
73 log::warn!("Sync did not complete, see the previous log lines for more info. You can safely start a new sync. The new task may not have been synced.");
74 } else {
75 println!("Done syncing the new task '{}' and the new calendar '{}'", new_task_name, new_calendar_name);
76 }
77 provider.local().save_to_folder().unwrap();
78
79 complete_item_and_sync_again(provider, &changed_calendar_url, &new_url).await;
80}pub fn uid(&self) -> &str
pub fn name(&self) -> &str
Sourcepub fn completed(&self) -> bool
pub fn completed(&self) -> bool
Examples found in repository?
examples/toggle-completions.rs (line 44)
37async fn toggle_all_tasks_and_sync_again(provider: &mut CalDavProvider) -> Result<(), Box<dyn Error>> {
38 let mut n_toggled = 0;
39
40 for (_url, cal) in provider.local().get_calendars_sync()?.iter() {
41 for (_url, item) in cal.lock().unwrap().get_items_mut_sync()?.iter_mut() {
42 match item {
43 Item::Task(task) => {
44 match task.completed() {
45 false => task.set_completion_status(CompletionStatus::Completed(Some(Utc::now()))),
46 true => task.set_completion_status(CompletionStatus::Uncompleted),
47 };
48 n_toggled += 1;
49 }
50 Item::Event(_) => {
51 // Not doing anything with calendar events
52 },
53 }
54 }
55 }
56
57 println!("{} items toggled.", n_toggled);
58 println!("Syncing...");
59
60 provider.sync().await;
61
62 println!("Syncing complete.");
63
64 Ok(())
65}pub fn ical_prod_id(&self) -> &str
pub fn sync_status(&self) -> &SyncStatus
pub fn last_modified(&self) -> &DateTime<Utc>
pub fn creation_date(&self) -> Option<&DateTime<Utc>>
pub fn completion_status(&self) -> &CompletionStatus
pub fn extra_parameters(&self) -> &[Property]
pub fn set_sync_status(&mut self, new_status: SyncStatus)
Sourcepub fn set_name(&mut self, new_name: String)
pub fn set_name(&mut self, new_name: String)
Rename a task. This updates its “last modified” field
Sourcepub fn set_completion_status(&mut self, new_completion_status: CompletionStatus)
pub fn set_completion_status(&mut self, new_completion_status: CompletionStatus)
Set the completion status
Examples found in repository?
examples/provider-sync.rs (line 94)
82async fn complete_item_and_sync_again(
83 provider: &mut CalDavProvider,
84 changed_calendar_url: &Url,
85 url_to_complete: &Url)
86{
87 println!("\nNow, we'll mark this last task as completed, and run the sync again.");
88 pause();
89
90 let completion_status = CompletionStatus::Completed(Some(Utc::now()));
91 provider.local().get_calendar(changed_calendar_url).await.unwrap()
92 .lock().unwrap().get_item_by_url_mut(url_to_complete).await.unwrap()
93 .unwrap_task_mut()
94 .set_completion_status(completion_status);
95
96 if provider.sync().await == false {
97 log::warn!("Sync did not complete, see the previous log lines for more info. You can safely start a new sync. The new task may not have been synced.");
98 } else {
99 println!("Done syncing the completed task");
100 }
101 provider.local().save_to_folder().unwrap();
102
103 remove_items_and_sync_again(provider, changed_calendar_url, url_to_complete).await;
104}More examples
examples/toggle-completions.rs (line 45)
37async fn toggle_all_tasks_and_sync_again(provider: &mut CalDavProvider) -> Result<(), Box<dyn Error>> {
38 let mut n_toggled = 0;
39
40 for (_url, cal) in provider.local().get_calendars_sync()?.iter() {
41 for (_url, item) in cal.lock().unwrap().get_items_mut_sync()?.iter_mut() {
42 match item {
43 Item::Task(task) => {
44 match task.completed() {
45 false => task.set_completion_status(CompletionStatus::Completed(Some(Utc::now()))),
46 true => task.set_completion_status(CompletionStatus::Uncompleted),
47 };
48 n_toggled += 1;
49 }
50 Item::Event(_) => {
51 // Not doing anything with calendar events
52 },
53 }
54 }
55 }
56
57 println!("{} items toggled.", n_toggled);
58 println!("Syncing...");
59
60 provider.sync().await;
61
62 println!("Syncing complete.");
63
64 Ok(())
65}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more