Review generated job removal

from Ownership
Rust 1.98 advanced 6 min 4 issues to find

Review this generated queue helper.

Remove and return the first case-sensitive match, leave the queue unchanged when absent, perform one linear scan without duplicating the list, and produce no output.

Rust
fn take_job(queue: &mut Vec<String>, target: &str) -> Option<String> {
    let snapshot = queue.clone();
    let mut match_index = None;

    for (index, job) in snapshot.iter().enumerate() {
        if job.to_lowercase() == target.to_lowercase() {
            match_index = Some(index);
        }
    }

    println!("taking {target}");

    match match_index {
        Some(index) => Some(queue.remove(index)),
        None => None,
    }
}

generated code is illustrative, not from any one model

Open in playground
Report an error