mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat: impl so no longer needed from::
Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
parent
79f132236f
commit
8b704fa668
4 changed files with 11 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue