Use Sender directly instead of a boxed closure

This commit is contained in:
mo8it 2024-08-09 23:24:57 +02:00
parent 56f63dfd8a
commit cb6b2ab5ba
2 changed files with 6 additions and 7 deletions

View file

@ -109,7 +109,7 @@ pub(crate) struct FlycheckHandle {
impl FlycheckHandle {
pub(crate) fn spawn(
id: usize,
sender: Box<dyn Fn(FlycheckMessage) + Send>,
sender: Sender<FlycheckMessage>,
config: FlycheckConfig,
sysroot_root: Option<AbsPathBuf>,
workspace_root: AbsPathBuf,
@ -199,7 +199,7 @@ enum StateChange {
struct FlycheckActor {
/// The workspace id of this flycheck instance.
id: usize,
sender: Box<dyn Fn(FlycheckMessage) + Send>,
sender: Sender<FlycheckMessage>,
config: FlycheckConfig,
manifest_path: Option<AbsPathBuf>,
/// Either the workspace root of the workspace we are flychecking,
@ -235,7 +235,7 @@ pub(crate) const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
impl FlycheckActor {
fn new(
id: usize,
sender: Box<dyn Fn(FlycheckMessage) + Send>,
sender: Sender<FlycheckMessage>,
config: FlycheckConfig,
sysroot_root: Option<AbsPathBuf>,
workspace_root: AbsPathBuf,
@ -479,7 +479,7 @@ impl FlycheckActor {
}
fn send(&self, check_task: FlycheckMessage) {
(self.sender)(check_task);
self.sender.send(check_task).unwrap();
}
}

View file

@ -758,7 +758,7 @@ impl GlobalState {
self.flycheck = match invocation_strategy {
crate::flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn(
0,
Box::new(move |msg| sender.send(msg).unwrap()),
sender,
config,
None,
self.config.root_path().clone(),
@ -793,10 +793,9 @@ impl GlobalState {
))
})
.map(|(id, (root, manifest_path), sysroot_root)| {
let sender = sender.clone();
FlycheckHandle::spawn(
id,
Box::new(move |msg| sender.send(msg).unwrap()),
sender.clone(),
config.clone(),
sysroot_root,
root.to_path_buf(),