Task

Struct Task 

Source
pub struct Task { /* private fields */ }
Expand description

A to-do task

Implementations§

Source§

impl Task

Source

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}
Source

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

Source

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}
Source

pub fn uid(&self) -> &str

Source

pub fn name(&self) -> &str

Source

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}
Source

pub fn ical_prod_id(&self) -> &str

Source

pub fn sync_status(&self) -> &SyncStatus

Source

pub fn last_modified(&self) -> &DateTime<Utc>

Source

pub fn creation_date(&self) -> Option<&DateTime<Utc>>

Source

pub fn completion_status(&self) -> &CompletionStatus

Source

pub fn extra_parameters(&self) -> &[Property]

Source

pub fn set_sync_status(&mut self, new_status: SyncStatus)

Source

pub fn set_name(&mut self, new_name: String)

Rename a task. This updates its “last modified” field

Source

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
Hide additional 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 Clone for Task

Source§

fn clone(&self) -> Task

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Task

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Task

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Task

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,