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

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 = 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.