fn schedule_according_to_importance(
        &mut self,
        start: DateTime<Utc>,
        mut tasks: Vec<Rc<TaskT>>,
    ) -> Result<(), Error<TaskT>> {
        // Start by scheduling the least important tasks closest to the deadline, and so on.
        tasks.sort_by_key(|task| {
            (
                task.importance(),
                start.signed_duration_since(task.deadline()),
            )
        });
        for task in &tasks {
            if task.deadline() < start + task.duration() {
                return Err(Error::DeadlineMissed {
                    task: (**task).clone(),
                    tense: if task.deadline() < start {
                        "missed"
                    } else {
                        "will miss"
                    },
                });
            }
            if !self.schedule_close_before(
                task.deadline(),
                task.duration(),
                Some(start),
                Item::Task(Rc::clone(task)),
            ) {
                return Err(Error::NotEnoughTime {
                    task: (**task).clone(),
                });
            }
        }
        // Next, shift the most important tasks towards today, and so on, filling up the gaps.
        // Keep repeating that, until nothing changes anymore (i.e. all gaps are filled).
        let mut changed = !self.is_empty();
        while changed {
            changed = false;
            for task in tasks.iter().rev() {
                let scheduled_entry = self
                    .unschedule(&Item::Task(task.clone()))
                    .ok_or_else(|| Error::Internal("I couldn't unschedule a task"))?;
                if !self.schedule_close_after(
                    start,
                    task.duration(),
                    Some(scheduled_entry.end),
                    scheduled_entry.data,
                ) {
                    return Err(Error::Internal("I couldn't reschedule a task"));
                }
                let new_start =
                    self.when_scheduled(&Item::Task(task.clone()))
                        .ok_or_else(|| {
                            Error::Internal("I couldn't find a task that was just scheduled")
                        })?;
                if scheduled_entry.start != *new_start {
                    changed = true;
                    break;
                }
            }
        }
        Ok(())
    }
/// Schedules `tasks` according to importance while making sure all deadlines are met.
///
/// First, all tasks --- starting with the least important until the most important --- are
/// scheduled as close as possible to their deadline. Next, all tasks --- starting with the
/// most important until the least important --- are put as close to the present as possible.
/// For ties on importance, more urgent tasks are scheduled later in the first phase and sooner
/// in the second phase.
///
/// This algorithm has a terrible performance at the moment and it doesn't work right when the
/// lengths of the tasks aren't about the same, but it will do for now.
Schedules `tasks` according to importance while making sure all deadlines are met.

This algorithm has a terrible performance at the moment and it doesn't work right when the
lengths of the tasks aren't about the same, but it will do for now.
Schedules ` tasks ` according to importance while making sure all deadlines are met . This algorithm has a terrible performance at the moment and it doesn ' t work right when the lengths of the tasks aren ' t about the same but it will do for now .
fn schedule_according_to_importance(
        &mut self,
        start: DateTime<Utc>,
        mut tasks: Vec<Rc<TaskT>>,
    ) -> Result<(), Error<TaskT>> {
        // Start by scheduling the least important tasks closest to the deadline, and so on.
        tasks.sort_by_key(|task| {
            (
                task.importance(),
                start.signed_duration_since(task.deadline()),
            )
        });
        for task in &tasks {
            if task.deadline() < start + task.duration() {
                return Err(Error::DeadlineMissed {
                    task: (**task).clone(),
                    tense: if task.deadline() < start {
                        "missed"
                    } else {
                        "will miss"
                    },
                });
            }
            if !self.schedule_close_before(
                task.deadline(),
                task.duration(),
                Some(start),
                Item::Task(Rc::clone(task)),
            ) {
                return Err(Error::NotEnoughTime {
                    task: (**task).clone(),
                });
            }
        }
        // Next, shift the most important tasks towards today, and so on, filling up the gaps.
        // Keep repeating that, until nothing changes anymore (i.e. all gaps are filled).
        let mut changed = !self.is_empty();
        while changed {
            changed = false;
            for task in tasks.iter().rev() {
                let scheduled_entry = self
                    .unschedule(&Item::Task(task.clone()))
                    .ok_or_else(|| Error::Internal("I couldn't unschedule a task"))?;
                if !self.schedule_close_after(
                    start,
                    task.duration(),
                    Some(scheduled_entry.end),
                    scheduled_entry.data,
                ) {
                    return Err(Error::Internal("I couldn't reschedule a task"));
                }
                let new_start =
                    self.when_scheduled(&Item::Task(task.clone()))
                        .ok_or_else(|| {
                            Error::Internal("I couldn't find a task that was just scheduled")
                        })?;
                if scheduled_entry.start != *new_start {
                    changed = true;
                    break;
                }
            }
        }
        Ok(())
    }
fn schedule_according_to_importance ( & mut self , start : DateTime < Utc > , mut tasks : Vec < Rc < TaskT > > , ) -> Result < ( ) , Error < TaskT > > { // Start by scheduling the least important tasks closest to the deadline, and so on. tasks . sort_by_key ( | task | { ( task . importance ( ) , start . signed_duration_since ( task . deadline ( ) ) , ) } ) ; for task in & tasks { if task . deadline ( ) < start + task . duration ( ) { return Err ( Error :: DeadlineMissed { task : ( * * task ) . clone ( ) , tense : if task . deadline ( ) < start { " " } else { " " } , } ) ; } if ! self . schedule_close_before ( task . deadline ( ) , task . duration ( ) , Some ( start ) , Item :: Task ( Rc :: clone ( task ) ) , ) { return Err ( Error :: NotEnoughTime { task : ( * * task ) . clone ( ) , } ) ; } } // Next, shift the most important tasks towards today, and so on, filling up the gaps. // Keep repeating that, until nothing changes anymore (i.e. all gaps are filled). let mut changed = ! self . is_empty ( ) ; while changed { changed = false ; for task in tasks . iter ( ) . rev ( ) { let scheduled_entry = self . unschedule ( & Item :: Task ( task . clone ( ) ) ) . ok_or_else ( | | Error :: Internal ( " " ) ) ? ; if ! self . schedule_close_after ( start , task . duration ( ) , Some ( scheduled_entry . end ) , scheduled_entry . data , ) { return Err ( Error :: Internal ( " " ) ) ; } let new_start = self . when_scheduled ( & Item :: Task ( task . clone ( ) ) ) . ok_or_else ( | | { Error :: Internal ( " " ) } ) ? ; if scheduled_entry . start != * new_start { changed = true ; break ; } } } Ok ( ( ) ) }
Schedules `tasks` according to importance while making sure all deadlines are met.
Schedules ` tasks ` according to importance while making sure all deadlines are met .
&mut self
start
DateTime<Utc>
tasks
Vec<Rc<TaskT>>
&mut self
start
DateTime<Utc>
tasks
Vec<Rc<TaskT>>