feat: impl so no longer needed from::

Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
əlemi 2024-08-15 22:47:49 +02:00
parent 79f132236f
commit 8b704fa668
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 11 additions and 7 deletions

View file

@ -45,8 +45,12 @@ pub trait Controller<T : Sized + Send + Sync> : Sized + Send + Sync {
}
}
fn callback(&self, cb: ControllerCallback<Self>);
/// registers a callback to be called on receive.
///
/// there can only be one callback at any given time.
fn callback(&self, cb: impl Into<ControllerCallback<Self>>);
/// clears the currently registered callback.
fn clear_callback(&self);
/// block until next value is available without consuming it

View file

@ -98,8 +98,8 @@ impl Controller<TextChange> for BufferController {
Ok(())
}
fn callback(&self, cb: ControllerCallback<BufferController>) {
if self.0.callback.send(Some(cb)).is_err() {
fn callback(&self, cb: impl Into<ControllerCallback<BufferController>>) {
if self.0.callback.send(Some(cb.into())).is_err() {
// TODO should we panic? we failed what we were supposed to do
tracing::error!("no active buffer worker to run registered callback!");
}

View file

@ -63,8 +63,8 @@ impl Controller<Cursor> for CursorController {
Ok(self.0.last_op.lock().await.changed().await?)
}
fn callback(&self, cb: ControllerCallback<CursorController>) {
if self.0.callback.send(Some(cb)).is_err() {
fn callback(&self, cb: impl Into<ControllerCallback<CursorController>>) {
if self.0.callback.send(Some(cb.into())).is_err() {
// TODO should we panic? we failed what we were supposed to do
tracing::error!("no active cursor worker to run registered callback!");
}

View file

@ -207,12 +207,12 @@ impl LuaUserData for CodempBufferController {
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
methods.add_method("callback", |_, this, (cb,):(LuaFunction,)| {
this.callback(ControllerCallback::from(move |controller: CodempBufferController| {
this.callback(move |controller: CodempBufferController| {
let _c = controller.clone();
if let Err(e) = cb.call::<(CodempBufferController,), ()>((controller,)) {
tracing::error!("error running buffer#{} callback: {e}", _c.name());
}
}));
});
Ok(())
});
}