pub fn archive() -> Result<usize, String> {
    let tasks = read_todo_file()?;
    let completed_tasks = locate_completed_tasks(&tasks);

    let completed_tasks_str =
        completed_tasks
            .iter()
            .fold(String::new(), |mut serialized, (_, task)| {
                serialized.push_str(task);
                serialized.push('\n');
                serialized
            });
    let mut done_file = OpenOptions::new()
        .append(true)
        .open(DONETXT_PATH)
        .map_err(|e| e.to_string())?;
    done_file
        .write(completed_tasks_str.as_bytes())
        .map_err(|e| e.to_string())?;

    let completed_tasks_ids = completed_tasks.iter().map(|(id, _)| *id).collect();
    let filtered_tasks = remove_tasks(completed_tasks_ids, &tasks)?;
    overwrite_todo_file(&filtered_tasks)?;
    Ok(completed_tasks.len())
}
/// Moves completed tasks to the archive file (done.txt)
///
/// When the operation is completed, the function returns the number of moved tasks.
Moves completed tasks to the archive file (done.txt)
When the operation is completed, the function returns the number of moved tasks.
Moves completed tasks to the archive file ( done . txt ) When the operation is completed the function returns the number of moved tasks .
pub fn archive() -> Result<usize, String> {
    let tasks = read_todo_file()?;
    let completed_tasks = locate_completed_tasks(&tasks);
    let completed_tasks_str =
        completed_tasks
            .iter()
            .fold(String::new(), |mut serialized, (_, task)| {
                serialized.push_str(task);
                serialized.push('\n');
                serialized
            });
    let mut done_file = OpenOptions::new()
        .append(true)
        .open(DONETXT_PATH)
        .map_err(|e| e.to_string())?;
    done_file
        .write(completed_tasks_str.as_bytes())
        .map_err(|e| e.to_string())?;
    let completed_tasks_ids = completed_tasks.iter().map(|(id, _)| *id).collect();
    let filtered_tasks = remove_tasks(completed_tasks_ids, &tasks)?;
    overwrite_todo_file(&filtered_tasks)?;
    Ok(completed_tasks.len())
}
pub fn archive ( ) -> Result < usize , String > { let tasks = read_todo_file ( ) ? ; let completed_tasks = locate_completed_tasks ( & tasks ) ; let completed_tasks_str = completed_tasks . iter ( ) . fold ( String :: new ( ) , | mut serialized , ( _ , task ) | { serialized . push_str ( task ) ; serialized . push ( '\n' ) ; serialized } ) ; let mut done_file = OpenOptions :: new ( ) . append ( true ) . open ( DONETXT_PATH ) . map_err ( | e | e . to_string ( ) ) ? ; done_file . write ( completed_tasks_str . as_bytes ( ) ) . map_err ( | e | e . to_string ( ) ) ? ; let completed_tasks_ids = completed_tasks . iter ( ) . map ( | ( id , _ ) | * id ) . collect ( ) ; let filtered_tasks = remove_tasks ( completed_tasks_ids , & tasks ) ? ; overwrite_todo_file ( & filtered_tasks ) ? ; Ok ( completed_tasks . len ( ) ) }
Moves completed tasks to the archive file (done.txt)
When the operation is completed, the function returns the number of moved tasks.
Moves completed tasks to the archive file ( done . txt ) When the operation is completed the function returns the number of moved tasks .