pub struct Project { /* private fields */ }Expand description
Represents a project with a name and a list of resources.
Implementations§
Source§impl Project
impl Project
Sourcepub fn builder() -> ProjectBuilder
pub fn builder() -> ProjectBuilder
Create an instance of Project using the builder syntax
Source§impl Project
impl Project
Sourcepub fn name(&self) -> &str
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");Sourcepub fn description(&self) -> Option<&str>
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);Sourcepub fn add_task(&mut self, task: Task)
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);Sourcepub fn rm_task(&mut self, i: usize) -> Result<()>
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);Sourcepub fn task(&self, index: usize) -> Option<&Task>
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");Sourcepub fn task_mut(&mut self, index: usize) -> Option<&mut Task>
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")Sourcepub fn tasks(&self) -> impl Iterator<Item = &Task>
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);Sourcepub fn tasks_mut(&mut self) -> impl Iterator<Item = &mut Task>
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);Sourcepub fn add_time_relationship(
&mut self,
predecessor_index: usize,
successor_index: usize,
kind: TimeRelationship,
) -> Result<()>
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")Sourcepub fn remove_time_relationship(
&mut self,
predecessor_index: usize,
successor_index: usize,
) -> Result<()>
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);Sourcepub fn successors(&self, node_index: usize) -> impl Iterator<Item = &Task>
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")Sourcepub fn successors_indices(
&self,
node_index: usize,
) -> impl Iterator<Item = usize>
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)Sourcepub fn predecessors(&self, node_index: usize) -> impl Iterator<Item = &Task>
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")Sourcepub fn predecessors_indices(
&self,
node_index: usize,
) -> impl Iterator<Item = usize>
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)Sourcepub fn update_predecessors(
&mut self,
task_index: usize,
predecessors_indices: &[usize],
) -> Result<()>
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);Sourcepub fn update_successors(
&mut self,
task_index: usize,
successors_indices: &[usize],
) -> Result<()>
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);Sourcepub fn add_subtask(&mut self, parent_index: usize, child_index: usize)
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);Sourcepub fn subtasks(&self, task_index: usize) -> Vec<usize>
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);Sourcepub fn start_date(&self) -> Option<DateTime<Utc>>
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));Sourcepub fn add_resource(&mut self, resource: Resource)
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);Sourcepub fn resource(&self, index: usize) -> Option<&Resource>
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());Sourcepub fn rm_resource(&mut self, index: usize) -> Resource
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());Sourcepub fn resource_mut(&mut self, index: usize) -> Option<&mut Resource>
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");
}
}Sourcepub fn resources(&self) -> &[Resource]
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);Sourcepub fn res_into_consumable(
&mut self,
resource_index: usize,
) -> Result<(), ResourceConversionError>
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 aConsumable
§Errors
ResourceConversionError::ResourceNotFound- If a resource with the specified index does not exist.ResourceConversionError::ConversionNotPossible- When trying to convert a resource that’s not aMaterial.
§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());Sourcepub fn res_into_nonconsumable(
&mut self,
resource_index: usize,
) -> Result<(), ResourceConversionError>
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 aNonConsumable
§Errors
ResourceConversionError::ResourceNotFound- If a resource with the specified index does not exist.ResourceConversionError::ConversionNotPossible- When trying to convert a resource that’s not aMaterial.
§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());Sourcepub fn add_stakeholder(&mut self, stakeholder: Stakeholder)
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);Sourcepub fn stakeholders(&self) -> &[Stakeholder]
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§
Auto Trait Implementations§
impl Freeze for Project
impl RefUnwindSafe for Project
impl Send for Project
impl Sync for Project
impl Unpin for Project
impl UnwindSafe for Project
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> 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