Review generated audit handler

from Closures
Rust 1.98 advanced 6 min 4 issues to find

Review this generated audit callback factory.

Return a reusable callback that can move to a worker thread, records every supplied message without output, avoids copying history, and remains usable after a poisoned lock.

Rust
use std::sync::{Arc, Mutex};

fn make_audit_handler(
    prefix: String,
    entries: Arc<Mutex<Vec<String>>>,
) -> Box<dyn FnMut(String) + Send + 'static> {
    Box::new(move |message| {
        let previous = entries.lock().unwrap().clone();
        if message.trim().is_empty() {
            return;
        }
        entries.lock().unwrap().push(format!("{prefix}:{message}"));
        println!("previous={previous:?}");
    })
}

generated code is illustrative, not from any one model

Open in playground
Report an error