prek 0.3.11

A fast Git hook manager written in Rust, designed as a drop-in alternative to pre-commit, reimagined.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::sync::Mutex;

static CLEANUP_HOOKS: Mutex<Vec<Box<dyn Fn() + Send>>> = Mutex::new(Vec::new());

/// Run all cleanup functions.
pub fn cleanup() {
    let mut cleanup = CLEANUP_HOOKS.lock().unwrap();
    for f in cleanup.drain(..) {
        f();
    }
}

/// Add a cleanup function to be run when the program is interrupted.
pub fn add_cleanup<F: Fn() + Send + 'static>(f: F) {
    let mut cleanup = CLEANUP_HOOKS.lock().unwrap();
    cleanup.push(Box::new(f));
}