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

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

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

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

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

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

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

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

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

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

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§

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 Default for Task

Source§

fn default() -> Task

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Task

Source§

fn eq(&self, other: &Task) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Task

Source§

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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 = 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.