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 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 duration is already set, the finish time will be updated accordingly. If there is a finish time set, but not a duration, the duration will be updated accordingly. The finish time will be pushed ahead if the start time is after the finish time.
§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, Duration};
use planter_core::task::Task;
let mut task = Task::new("Become world leader");
let start_time = Utc::now();
task.edit_start(start_time);
assert_eq!(task.start().unwrap(), start_time);Sourcepub fn start(&self) -> Option<DateTime<Utc>>
pub 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);
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 there is a start time already set, duration will be updated accordingly. Start time will be pushed back if it’s after the finish time.
§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 fn finish(&self) -> Option<DateTime<Utc>>
pub 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);
assert_eq!(task.finish().unwrap(), finish_time);Sourcepub fn edit_duration(&mut self, duration: PositiveDuration)
pub fn edit_duration(&mut self, duration: PositiveDuration)
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::PositiveDuration};
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 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 description(&self) -> &str
pub fn description(&self) -> &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(), "Description");Sourcepub fn completed(&self) -> bool
pub 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 fn toggle_completed(&mut self)
pub 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 fn duration(&self) -> Option<PositiveDuration>
pub fn duration(&self) -> Option<PositiveDuration>
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§
impl Eq for Task
impl StructuralPartialEq for Task
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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