fn fill_slot(
    slot: FreeSlot,
    tasks: &mut Vec<(ClassAsynchronousTask, StudentClassAsynchronousTask)>,
    events_to_add: &mut Vec<Event>,
) {
    if tasks.is_empty() {
        return;
    }
    let len = slot.end - slot.start;
    if len > Duration::minutes(25) {
        let (task, _) = tasks.pop().unwrap();
        events_to_add.push(
            Event::new()
                .uid(&Uuid::new_v4().to_string())
                .starts(slot.start)
                .ends(slot.start.add(Duration::minutes(25)))
                .summary(
                    format!(
                        "Task title: {} Task description: {}",
                        task.title, task.description
                    )
                    .chars()
                    .map(|char| if char == '\n' { ' ' } else { char })
                    .collect::<String>()
                    .as_str(),
                )
                .done(),
        );
        fill_slot(
            FreeSlot {
                start: slot.start + Duration::minutes(25),
                end: slot.end,
            },
            tasks,
            events_to_add,
        );
    }
}
/// Recursively occupies the provided time slot with as many events as possible.
Recursively occupies the provided time slot with as many events as possible.
Recursively occupies the provided time slot with as many events as possible .
fn fill_slot(
    slot: FreeSlot,
    tasks: &mut Vec<(ClassAsynchronousTask, StudentClassAsynchronousTask)>,
    events_to_add: &mut Vec<Event>,
) {
    if tasks.is_empty() {
        return;
    }
    let len = slot.end - slot.start;
    if len > Duration::minutes(25) {
        let (task, _) = tasks.pop().unwrap();
        events_to_add.push(
            Event::new()
                .uid(&Uuid::new_v4().to_string())
                .starts(slot.start)
                .ends(slot.start.add(Duration::minutes(25)))
                .summary(
                    format!(
                        "Task title: {} Task description: {}",
                        task.title, task.description
                    )
                    .chars()
                    .map(|char| if char == '\n' { ' ' } else { char })
                    .collect::<String>()
                    .as_str(),
                )
                .done(),
        );
        fill_slot(
            FreeSlot {
                start: slot.start + Duration::minutes(25),
                end: slot.end,
            },
            tasks,
            events_to_add,
        );
    }
}
fn fill_slot ( slot : FreeSlot , tasks : & mut Vec < ( ClassAsynchronousTask , StudentClassAsynchronousTask ) > , events_to_add : & mut Vec < Event > , ) { if tasks . is_empty ( ) { return ; } let len = slot . end - slot . start ; if len > Duration :: minutes ( 25 ) { let ( task , _ ) = tasks . pop ( ) . unwrap ( ) ; events_to_add . push ( Event :: new ( ) . uid ( & Uuid :: new_v4 ( ) . to_string ( ) ) . starts ( slot . start ) . ends ( slot . start . add ( Duration :: minutes ( 25 ) ) ) . summary ( format ! ( " " task title task description ) . chars ( ) . map ( | char | if char == '\n' { ' ' } else { char } ) . collect :: < String > ( ) . as_str ( ) , ) . done ( ) , ) ; fill_slot ( FreeSlot { start : slot . start + Duration :: minutes ( 25 ) , end : slot . end , } , tasks , events_to_add , ) ; } }
Recursively occupies the provided time slot with as many events as possible.
Recursively occupies the provided time slot with as many events as possible .
slot
FreeSlot
tasks
&mut Vec<(ClassAsynchronousTask, StudentClassAsynchronousTask)>
events_to_add
&mut Vec<Event>