Skip to main content

Task

Struct Task 

Source
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

Source

pub fn new(name: impl Into<String>) -> Self

Creates a new task with the given name.

§Arguments
  • name - The name of the task.
§Returns

A new task with the given name.

§Example
use planter_core::task::Task;

let task = Task::new("Become world leader");
assert_eq!(task.name(), "Become world leader");
Source

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();
Source

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);
Source

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);
Source

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);
Source

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);
Source

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());
Source

pub fn assignments(&self) -> impl Iterator<Item = (Uuid, u32)> + '_

Iterates the task’s resource assignments as (resource_id, quantity) pairs, in the order they were assigned: how many units of each engaged resource the task uses. Populate them with crate::project::Project::assign_resource.

§Example
use planter_core::task::Task;

assert_eq!(Task::new("Become world leader").assignments().count(), 0);
Source

pub fn assignment(&self, resource_id: Uuid) -> Option<u32>

Returns how many units of resource_id this task engages, or None if it doesn’t engage it at all.

§Example
use planter_core::task::Task;
use uuid::Uuid;

assert_eq!(Task::new("Become world leader").assignment(Uuid::new_v4()), None);
Source

pub fn edit_name(&mut self, name: impl Into<String>)

Edits the name of the task.

§Arguments
  • name - The new name of the task.
§Example
use planter_core::task::Task;

let mut task = Task::new("Become world leader");
task.edit_name("Become world boss");
assert_eq!(task.name(), "Become world boss");
Source

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");
Source

pub fn edit_description(&mut self, description: impl Into<String>)

Edits the description of the task.

§Arguments
  • description - The new 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"));
Source

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());
Source

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"));
Source

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());
Source

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());
Source

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());
Source

pub fn duration_hours(&self) -> u64

Returns the task’s duration in whole hours, 0 if unset. This is the figure cost calculations multiply resource rates by; a partial hour is truncated, saturating at u64::MAX.

§Example
use chrono::Duration;
use planter_core::task::Task;

let mut task = Task::new("Become world leader");
assert_eq!(task.duration_hours(), 0);
task.edit_duration(Duration::minutes(150).try_into().unwrap());
assert_eq!(task.duration_hours(), 2);

Trait Implementations§

Source§

impl Clone for Task

Source§

fn clone(&self) -> Task

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

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> 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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.