Project

Struct Project 

Source
pub struct Project { /* private fields */ }
Expand description

Represents a project with a name and a list of resources.

Implementations§

Source§

impl Project

Source

pub fn builder() -> ProjectBuilder

Create an instance of Project using the builder syntax

Source§

impl Project

Source

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

Creates a new project with the given name.

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

A new Project instance.

§Example
use planter_core::project::Project;

let project = Project::new("World domination");
assert_eq!(project.name(), "World domination");
Source

pub fn name(&self) -> &str

Returns the name of the project.

§Example
use planter_core::project::Project;

let project = Project::new("World domination");
assert_eq!(project.name(), "World domination");
Source

pub fn description(&self) -> Option<&str>

Returns the description of the project.

§Example
use planter_core::project::Project;

let project = Project::new("World domination");
assert_eq!(project.description(), None);
Source

pub fn add_task(&mut self, task: Task)

Adds a task to the project.

§Arguments
  • task - The task to add to the project.
§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
assert_eq!(project.tasks().count(), 0);
project.add_task(Task::new("Become world leader"));
assert_eq!(project.tasks().count(), 1);
Source

pub fn rm_task(&mut self, i: usize) -> Result<()>

Deletes a task and all references to it from the project.

§Arguments
  • i - The index of the task.
§Errors

TODO!

§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
assert_eq!(project.tasks().count(), 1);
assert!(project.rm_task(0).is_ok());
assert_eq!(project.tasks().count(), 0);
Source

pub fn task(&self, index: usize) -> Option<&Task>

Gets a reference to the task with the given index from the project.

§Arguments
  • index - The index to identify the task.
§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
assert_eq!(project.task(0).unwrap().name(), "Become world leader");
Source

pub fn task_mut(&mut self, index: usize) -> Option<&mut Task>

Gets a mutable reference to the task with the given index from the project.

§Arguments
  • index - The index to identify the task.
§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
let task = project.task_mut(0).unwrap();
assert_eq!(task.name(), "Become world leader");

task.edit_name("Become world's biggest loser");
assert_eq!(task.name(), "Become world's biggest loser")
Source

pub fn tasks(&self) -> impl Iterator<Item = &Task>

Returns the tasks of the project.

§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
assert_eq!(project.tasks().count(), 1);
Source

pub fn tasks_mut(&mut self) -> impl Iterator<Item = &mut Task>

Returns a mutable reference to the tasks of the project.

§Example
use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
assert_eq!(project.tasks().count(), 1);
Source

pub fn add_time_relationship( &mut self, predecessor_index: usize, successor_index: usize, kind: TimeRelationship, ) -> Result<()>

Adds a relationship betwen tasks, where one is the predecessor and the other one a successor.

§Errors

TODO!

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(0, 1, TimeRelationship::default());

assert_eq!(project.successors(0).next().unwrap().name(), "Become world leader")
Source

pub fn remove_time_relationship( &mut self, predecessor_index: usize, successor_index: usize, ) -> Result<()>

Removes a relationship betwen tasks, where one is the predecessor and the other one a successor.

§Errors

TODO!

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(0, 1, TimeRelationship::default());
project.remove_time_relationship(0, 1);

assert_eq!(project.successors(0).count(), 0);
Source

pub fn successors(&self, node_index: usize) -> impl Iterator<Item = &Task>

Gets the list of successors for a given node.

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(0, 1, TimeRelationship::default());

assert_eq!(project.successors(0).next().unwrap().name(), "Become world leader")
Source

pub fn successors_indices( &self, node_index: usize, ) -> impl Iterator<Item = usize>

Gets the indices of all successors for a given node.

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(0, 1, TimeRelationship::default());

assert_eq!(project.successors_indices(0).next().unwrap(), 1)
Source

pub fn predecessors(&self, node_index: usize) -> impl Iterator<Item = &Task>

Gets the list of predecessors for a given node.

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(1, 0, TimeRelationship::default());

assert_eq!(project.predecessors(0).next().unwrap().name(), "Become world leader")
Source

pub fn predecessors_indices( &self, node_index: usize, ) -> impl Iterator<Item = usize>

Gets the indices of all predecessors for a given node.

§Example
use planter_core::{project::{Project, TimeRelationship}, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Get rich"));
project.add_task(Task::new("Become world leader"));
project.add_time_relationship(1, 0, TimeRelationship::default());

assert_eq!(project.predecessors_indices(0).next().unwrap(), 1)
Source

pub fn update_predecessors( &mut self, task_index: usize, predecessors_indices: &[usize], ) -> Result<()>

Updates the project by making sure the predecessors for the task with index node_index are exactly the ones listed in predecessors_indices

§Arguments
  • task_index - The index whose predecessors need to be updated.
  • predecessors_indices - The indices of the predecessors.
§Errors

TODO!

§Example
use planter_core::{project::Project, task::Task};

let tasks = vec![
     Task::new("Become world leader"),
     Task::new("Get rich"),
     Task::new("Be evil")
];
let mut project = Project::builder().name("World domination").tasks(tasks).build();

project.update_predecessors(2, &[0, 1]);
assert_eq!(project.predecessors(2).count(), 2);
Source

pub fn update_successors( &mut self, task_index: usize, successors_indices: &[usize], ) -> Result<()>

Updates the project by making sure the successors for the task with index node_index are exactly the ones listed in successors_indices

§Arguments
  • task_index - The index whose successors need to be updated.
  • successors_indices - The indices of the successors.
§Errors

TODO!

§Example
use planter_core::{project::Project, task::Task};

let tasks = vec![
     Task::new("Become world leader"),
     Task::new("Get rich"),
     Task::new("Be evil")
];
let mut project = Project::builder().name("World domination").tasks(tasks).build();

project.update_successors(0, &[1, 2]);
assert_eq!(project.successors(0).count(), 2);
Source

pub fn add_subtask(&mut self, parent_index: usize, child_index: usize)

Adds a subtask to a given task. This relationship means that the parent task is completed when all the children are completed. Also, the parent’s cost and duration is the cumulative cost and duration of the children.

Example

use planter_core::{project::Project, task::Task};

let tasks = vec![
     Task::new("Become world leader"),
     Task::new("Get rich"),
     Task::new("Be evil")
];
let mut project = Project::builder().name("World domination").tasks(tasks).build();

project.add_subtask(0, 1);
project.add_subtask(0, 2);
assert_eq!(project.subtasks(0).len(), 2);
Source

pub fn subtasks(&self, task_index: usize) -> Vec<usize>

Gets a list of all the subtasks of the given task.

Example

use planter_core::{project::Project, task::Task};

let mut project = Project::new("World domination");
project.add_task(Task::new("Become world leader"));
project.add_task(Task::new("Get rich"));
assert_eq!(project.subtasks(0).len(), 0);

project.add_subtask(0, 1);
assert_eq!(project.subtasks(0).len(), 1);
Source

pub fn start_date(&self) -> Option<DateTime<Utc>>

Returns the start date of the project.

§Example
use planter_core::{project::Project};
use chrono::Utc;

let start_date = Utc::now();
let mut project = Project::builder().name("World domination").start_date(start_date).build();
assert_eq!(project.start_date(), Some(start_date));
Source

pub fn add_resource(&mut self, resource: Resource)

Adds a resource to the project.

§Arguments
  • resource - The resource to add to the project.
§Example
use planter_core::{resources::Resource, project::Project, person::Person};

let mut project = Project::new("World domination");
project.add_resource(Resource::Personnel {
    person: Person::new("Sebastiano", "Giordano").unwrap(),
    hourly_rate: None,
});
assert_eq!(project.resources().len(), 1);
Source

pub fn resource(&self, index: usize) -> Option<&Resource>

Get a reference to a resource used in the project.

§Example
use planter_core::{resources::Resource, project::Project, person::Person};

let mut project = Project::new("World domination");
project.add_resource(Resource::Personnel {
    person: Person::new("Sebastiano", "Giordano").unwrap(),
    hourly_rate: None,
});

assert!(project.resource(0).is_some());
Source

pub fn rm_resource(&mut self, index: usize) -> Resource

Remove a resource from the project.

§Panics

Panics if the resource index is out of bounds.

§Example
use planter_core::{resources::Resource, project::Project, person::Person};

let mut project = Project::new("World domination");
project.add_resource(Resource::Personnel {
    person: Person::new("Sebastiano", "Giordano").unwrap(),
    hourly_rate: None,
});

assert!(project.resource(0).is_some());
project.rm_resource(0);
assert!(project.resource(0).is_none());

let result = std::panic::catch_unwind(move || {
    project.rm_resource(0);
});
assert!(result.is_err());
Source

pub fn resource_mut(&mut self, index: usize) -> Option<&mut Resource>

Get a mutable reference to a resource used in the project.

§Example
use planter_core::{resources::Resource, project::Project, person::Person};

let mut project = Project::new("World domination");
project.add_resource(Resource::Personnel {
    person: Person::new("Sebastiano", "Giordano").unwrap(),
    hourly_rate: None,
});

let resource = project.resource_mut(0).unwrap();
match resource {
  Resource::Material(_) => panic!(),
  Resource::Personnel {
    person,
    ..
  } => {
    person.update_first_name("Alessandro");
    assert_eq!(person.first_name(), "Alessandro");
  }
}
Source

pub fn resources(&self) -> &[Resource]

Returns a reference to the list of resources associated with the project.

§Example
use planter_core::{resources::{Resource, Material, NonConsumable}, project::Project};

let mut project = Project::new("World domination");
project.add_resource(Resource::Material(Material::NonConsumable(
   NonConsumable::new("Crowbar"),
)));
assert_eq!(project.resources().len(), 1);
Source

pub fn res_into_consumable( &mut self, resource_index: usize, ) -> Result<(), ResourceConversionError>

Converts a resource into a Consumable, if that’s possible.

§Arguments
  • resource_index - The index of a Material, that’s not a Consumable
§Errors
  • ResourceConversionError::ResourceNotFound - If a resource with the specified index does not exist.
  • ResourceConversionError::ConversionNotPossible - When trying to convert a resource that’s not a Material.
§Example
use planter_core::{resources::{Resource, Material, NonConsumable}, project::Project};

let mut project = Project::new("World domination");
project.add_resource(Resource::Material(Material::NonConsumable(
   NonConsumable::new("Crowbar"),
)));
assert!(project.res_into_consumable(0).is_ok());
Source

pub fn res_into_nonconsumable( &mut self, resource_index: usize, ) -> Result<(), ResourceConversionError>

Converts a resource into a NonConsumable, if that’s possible.

§Arguments
  • resource_index - The index of a Material, that’s not a NonConsumable
§Errors
  • ResourceConversionError::ResourceNotFound - If a resource with the specified index does not exist.
  • ResourceConversionError::ConversionNotPossible - When trying to convert a resource that’s not a Material.
§Example
use planter_core::{resources::{Resource, Material, Consumable}, project::Project};

let mut project = Project::new("World domination");
project.add_resource(Resource::Material(Material::Consumable(
   Consumable::new("Stimpack"),
)));
assert!(project.res_into_nonconsumable(0).is_ok());
Source

pub fn add_stakeholder(&mut self, stakeholder: Stakeholder)

Adds a stakeholder to the project.

§Arguments
  • stakeholder - The stakeholder to add to the project.
§Example
use planter_core::{stakeholders::Stakeholder, project::Project, person::Person};

let mut project = Project::new("World domination");
let person = Person::new("Margherita", "Hack").unwrap();
project.add_stakeholder(Stakeholder::Individual {
  person,
  description: None,
});
assert_eq!(project.stakeholders().len(), 1);
Source

pub fn stakeholders(&self) -> &[Stakeholder]

Returns a reference to the list of stakeholders associated with the project.

§Example
use planter_core::{stakeholders::Stakeholder, project::Project, person::Person};

let mut project = Project::new("World domination");
let person = Person::new("Margherita", "Hack").unwrap();
project.add_stakeholder(Stakeholder::Individual {
  person,
  description: None,
});
assert_eq!(project.stakeholders().len(), 1);

Trait Implementations§

Source§

impl Debug for Project

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Project

Source§

fn default() -> Project

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

Auto Trait Implementations§

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