use crate::ported::zle::comp_h::{Cexpl, Cmatch};
use crate::ported::zle::compcore::{allccs, expls, fmatches, matches};
use std::sync::{Arc, Mutex};
pub fn matches_arc() -> Arc<Mutex<Vec<Cmatch>>> {
Arc::clone(&matches.get_or_init(default_match_handle).lock().unwrap())
}
pub fn fmatches_arc() -> Arc<Mutex<Vec<Cmatch>>> {
Arc::clone(&fmatches.get_or_init(default_match_handle).lock().unwrap())
}
pub fn expls_arc() -> Arc<Mutex<Vec<Cexpl>>> {
Arc::clone(&expls.get_or_init(default_expl_handle).lock().unwrap())
}
pub fn allccs_arc() -> Arc<Mutex<Vec<String>>> {
Arc::clone(&allccs.get_or_init(default_ccs_handle).lock().unwrap())
}
#[allow(clippy::type_complexity)]
pub fn rebind_current(
lmatches: &Arc<Mutex<Vec<Cmatch>>>,
lfmatches: &Arc<Mutex<Vec<Cmatch>>>,
lexpls: &Arc<Mutex<Vec<Cexpl>>>,
lallccs: &Arc<Mutex<Vec<String>>>,
) {
*matches.get_or_init(default_match_handle).lock().unwrap() = Arc::clone(lmatches);
*fmatches.get_or_init(default_match_handle).lock().unwrap() = Arc::clone(lfmatches);
*expls.get_or_init(default_expl_handle).lock().unwrap() = Arc::clone(lexpls);
*allccs.get_or_init(default_ccs_handle).lock().unwrap() = Arc::clone(lallccs);
}
fn default_match_handle() -> Mutex<Arc<Mutex<Vec<Cmatch>>>> {
Mutex::new(Arc::new(Mutex::new(Vec::new())))
}
fn default_expl_handle() -> Mutex<Arc<Mutex<Vec<Cexpl>>>> {
Mutex::new(Arc::new(Mutex::new(Vec::new())))
}
fn default_ccs_handle() -> Mutex<Arc<Mutex<Vec<String>>>> {
Mutex::new(Arc::new(Mutex::new(Vec::new())))
}