fn switch(message: SwitchMessage, state: &SharedState) -> Message {
    let task_ids = vec![message.task_id_1, message.task_id_2];
    let statuses = vec![TaskStatus::Queued, TaskStatus::Stashed];
    let mut state = state.lock().unwrap();
    let (_, mismatching) = state.tasks_in_statuses(Some(task_ids.clone().to_vec()), statuses);
    if !mismatching.is_empty() {
        return create_failure_message("Tasks have to be either queued or stashed.");
    }

    // Get the tasks. Expect them to be there, since we found no mismatch
    let mut first_task = state.tasks.remove(&task_ids[0]).unwrap();
    let mut second_task = state.tasks.remove(&task_ids[1]).unwrap();

    // Switch task ids
    let temp_id = first_task.id;
    first_task.id = second_task.id;
    second_task.id = temp_id;

    // Put tasks back in again
    state.tasks.insert(first_task.id, first_task);
    state.tasks.insert(second_task.id, second_task);

    create_success_message("Tasks have been switched")
}
/// Switch the position of two tasks in the upcoming queue
Switch the position of two tasks in the upcoming queue
Switch the position of two tasks in the upcoming queue
fn switch(message: SwitchMessage, state: &SharedState) -> Message {
    let task_ids = vec![message.task_id_1, message.task_id_2];
    let statuses = vec![TaskStatus::Queued, TaskStatus::Stashed];
    let mut state = state.lock().unwrap();
    let (_, mismatching) = state.tasks_in_statuses(Some(task_ids.clone().to_vec()), statuses);
    if !mismatching.is_empty() {
        return create_failure_message("Tasks have to be either queued or stashed.");
    }
    // Get the tasks. Expect them to be there, since we found no mismatch
    let mut first_task = state.tasks.remove(&task_ids[0]).unwrap();
    let mut second_task = state.tasks.remove(&task_ids[1]).unwrap();
    // Switch task ids
    let temp_id = first_task.id;
    first_task.id = second_task.id;
    second_task.id = temp_id;
    // Put tasks back in again
    state.tasks.insert(first_task.id, first_task);
    state.tasks.insert(second_task.id, second_task);
    create_success_message("Tasks have been switched")
}
fn switch ( message : SwitchMessage , state : & SharedState ) -> Message { let task_ids = vec ! [ message task_id_1 message task_id_2 ] ; let statuses = vec ! [ TaskStatus Queued TaskStatus Stashed ] ; let mut state = state . lock ( ) . unwrap ( ) ; let ( _ , mismatching ) = state . tasks_in_statuses ( Some ( task_ids . clone ( ) . to_vec ( ) ) , statuses ) ; if ! mismatching . is_empty ( ) { return create_failure_message ( " " ) ; } // Get the tasks. Expect them to be there, since we found no mismatch let mut first_task = state . tasks . remove ( & task_ids [ 0 ] ) . unwrap ( ) ; let mut second_task = state . tasks . remove ( & task_ids [ 1 ] ) . unwrap ( ) ; // Switch task ids let temp_id = first_task . id ; first_task . id = second_task . id ; second_task . id = temp_id ; // Put tasks back in again state . tasks . insert ( first_task . id , first_task ) ; state . tasks . insert ( second_task . id , second_task ) ; create_success_message ( " " ) }
Switch the position of two tasks in the upcoming queue
Switch the position of two tasks in the upcoming queue
message
SwitchMessage
state
&SharedState
message
SwitchMessage
state
&SharedState