pub struct Task { /* private fields */ }Expand description
A task is a unit of work that can be completed by a person or a group of people. It can be assigned resources and can have a start, finish, and duration.
Implementations§
Source§impl Task
impl Task
Sourcepub const fn id(&self) -> Uuid
pub const fn id(&self) -> Uuid
Returns the stable identifier of the task.
§Example
use planter_core::task::Task;
let task = Task::new("Become world leader");
let id = task.id();Sourcepub fn edit_start(&mut self, start: DateTime<Utc>) -> Result<()>
pub fn edit_start(&mut self, start: DateTime<Utc>) -> Result<()>
Edits the start time of the task.
If a finish time is already set, the duration is recalculated to finish - start.
If the new start time is after the finish time, the finish time is pushed
ahead to match, resulting in a zero duration.
§Arguments
start- The new start time of the task.
§Errors
Returns an error if the task has a finish date and the start date passed as parameter is too far from that.
§Example
use chrono::Utc;
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
let start_time = Utc::now();
task.edit_start(start_time).unwrap();
assert_eq!(task.start().unwrap(), start_time);Sourcepub const fn start(&self) -> Option<DateTime<Utc>>
pub const fn start(&self) -> Option<DateTime<Utc>>
Returns the start time of the task. It’s None by default.
§Example
use chrono::Utc;
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(task.start().is_none());
let start_time = Utc::now();
task.edit_start(start_time).unwrap();
assert_eq!(task.start().unwrap(), start_time);Sourcepub fn edit_finish(&mut self, finish: DateTime<Utc>) -> Result<()>
pub fn edit_finish(&mut self, finish: DateTime<Utc>) -> Result<()>
Edits the finish time of the task.
If a start time is already set, the duration is recalculated to finish - start.
If the new finish time is before the start time, the start time is pushed
back to match, resulting in a zero duration.
§Arguments
finish- The new finish time of the task.
§Errors
Returns an error if the task has a start date and the finish date passed as parameter is too far from that.
§Example
use chrono::Utc;
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(task.start().is_none());
let mut finish_time = Utc::now();
task.edit_finish(finish_time).unwrap();
assert_eq!(task.finish().unwrap(), finish_time);Sourcepub const fn finish(&self) -> Option<DateTime<Utc>>
pub const fn finish(&self) -> Option<DateTime<Utc>>
Returns the finish time of the task. It’s None by default.
§Example
use chrono::Utc;
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(task.finish().is_none());
let finish_time = Utc::now();
task.edit_finish(finish_time).unwrap();
assert_eq!(task.finish().unwrap(), finish_time);Sourcepub fn edit_duration(&mut self, duration: NonNegativeDuration)
pub fn edit_duration(&mut self, duration: NonNegativeDuration)
Edits the duration of the task. If the task has a start time, finish time will be updated accordingly.
§Arguments
duration- The new duration of the task.
§Example
use chrono::{Utc, Duration};
use planter_core::{task::Task, duration::NonNegativeDuration};
let mut task = Task::new("Become world leader");
task.edit_duration(Duration::minutes(30).try_into().unwrap());
assert!(task.duration().is_some());
assert_eq!(task.duration().unwrap(), Duration::minutes(30).try_into().unwrap());Sourcepub fn add_resource(&mut self, resource: Resource)
pub fn add_resource(&mut self, resource: Resource)
Adds a Resource to the task.
§Arguments
resource- The resource to add to the task.
§Example
use planter_core::{resources::{Resource, Material, NonConsumable}, task::Task};
let mut task = Task::new("Become world leader");
let resource = Resource::Material(Material::NonConsumable(
NonConsumable::new("Crowbar"),
));
task.add_resource(resource);
assert_eq!(task.resources().len(), 1);Sourcepub fn resources(&self) -> &[Resource]
pub fn resources(&self) -> &[Resource]
Returns the list of Resource assigned to the task.
§Example
use planter_core::task::Task;
use planter_core::resources::{Resource, Material, NonConsumable};
let mut task = Task::new("Become world leader");
assert!(task.resources().is_empty());
let resource = Resource::Material(Material::NonConsumable(
NonConsumable::new("Crowbar"),
));
task.add_resource(resource);
assert_eq!(task.resources().len(), 1);Sourcepub fn rm_resource(&mut self, index: usize) -> Option<Resource>
pub fn rm_resource(&mut self, index: usize) -> Option<Resource>
Removes a Resource from the task by index.
§Arguments
index- The index of the resource to remove.
§Returns
The removed resource, or None if the index is out of bounds.
§Example
use planter_core::{resources::{Resource, Material, NonConsumable}, task::Task};
let mut task = Task::new("Become world leader");
let resource = Resource::Material(Material::NonConsumable(
NonConsumable::new("Crowbar"),
));
task.add_resource(resource);
assert_eq!(task.resources().len(), 1);
let removed = task.rm_resource(0);
assert!(removed.is_some());
assert_eq!(task.resources().len(), 0);Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of the task.
§Example
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert_eq!(task.name(), "Become world leader");Sourcepub fn edit_description(&mut self, description: impl Into<String>)
pub fn edit_description(&mut self, description: impl Into<String>)
Sourcepub fn clear_description(&mut self)
pub fn clear_description(&mut self)
Clears the description of the task, setting it to None.
§Example
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
task.edit_description("Description");
assert_eq!(task.description(), Some("Description"));
task.clear_description();
assert!(task.description().is_none());Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Returns the description of the task.
§Example
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
task.edit_description("Description");
assert_eq!(task.description(), Some("Description"));Sourcepub const fn completed(&self) -> bool
pub const fn completed(&self) -> bool
Whether the task is completed. It’s false by default.
§Example
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(!task.completed());
task.toggle_completed();
assert!(task.completed());Sourcepub const fn toggle_completed(&mut self)
pub const fn toggle_completed(&mut self)
Marks the task as completed.
§Example
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(!task.completed());
task.toggle_completed();
assert!(task.completed());
task.toggle_completed();
assert!(!task.completed());Sourcepub const fn duration(&self) -> Option<NonNegativeDuration>
pub const fn duration(&self) -> Option<NonNegativeDuration>
Returns the duration of the task. It’s None by default.
§Example
use chrono::{Utc, Duration};
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
assert!(task.duration().is_none());
task.edit_duration(Duration::hours(1).try_into().unwrap());
assert!(task.duration().unwrap() == Duration::hours(1).try_into().unwrap());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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