Replacing unneeded trait with dyn FnOnce

This commit is contained in:
Pauan 2022-01-05 17:05:38 +01:00
parent 6c03a5a40a
commit a59bf02d59
1 changed files with 4 additions and 15 deletions

View File

@ -2,19 +2,6 @@ use std;
use discard::Discard; use discard::Discard;
// TODO replace this with FnOnce later
trait IInsertCallback {
fn call(self: Box<Self>, callbacks: &mut Callbacks);
}
impl<F: FnOnce(&mut Callbacks)> IInsertCallback for F {
#[inline]
fn call(self: Box<Self>, callbacks: &mut Callbacks) {
self(callbacks);
}
}
// TODO a bit gross // TODO a bit gross
trait IRemove { trait IRemove {
fn remove(self: Box<Self>); fn remove(self: Box<Self>);
@ -28,9 +15,11 @@ impl<A: Discard> IRemove for A {
} }
pub(crate) struct InsertCallback(Box<dyn IInsertCallback>); #[repr(transparent)]
pub(crate) struct InsertCallback(Box<dyn FnOnce(&mut Callbacks)>);
// TODO is there a more efficient way of doing this ? // TODO is there a more efficient way of doing this ?
#[repr(transparent)]
pub(crate) struct RemoveCallback(Box<dyn IRemove>); pub(crate) struct RemoveCallback(Box<dyn IRemove>);
impl std::fmt::Debug for InsertCallback { impl std::fmt::Debug for InsertCallback {
@ -84,7 +73,7 @@ impl Callbacks {
std::mem::swap(&mut callbacks.after_remove, &mut self.after_remove); std::mem::swap(&mut callbacks.after_remove, &mut self.after_remove);
for f in self.after_insert.drain(..) { for f in self.after_insert.drain(..) {
f.0.call(&mut callbacks); f.0(&mut callbacks);
} }
// TODO verify that this is correct // TODO verify that this is correct