审查这个生成的队列辅助函数。
移除并返回第一个区分大小写的匹配项;没有匹配时保持队列不变;只进行一次线性扫描且不复制列表;不得产生输出。
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,
}
}
生成代码仅作示例,不代表任何特定模型