Skip to content

Commit

Permalink
feat: impl so no longer needed from::
Browse files Browse the repository at this point in the history
Co-authored-by: zaaarf <me@zaaarf.foo>
  • Loading branch information
alemidev and zaaarf committed Aug 15, 2024
1 parent 79f1322 commit 8b704fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/api/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
4 changes: 2 additions & 2 deletions src/cursor/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
});
}
Expand Down

0 comments on commit 8b704fa

Please sign in to comment.