Closed thulasi-ram closed 1 year ago
My current use case below.. This gives compliation error: expected fn pointer, found closure
pub async fn adb_track_devices(c: &mut AdbTcpConnexion, tx: tokio::sync::MutexGuard<'_, Sender<String>>) -> Result<(), String> {
let callback = |device:adb_client::Device| {
let res = tx
.send(format!("{}", device))
.map_err(|e| e.to_string());
return res;
};
let res = c.track_devices(callback);
match res {
Err(e) => {
return Err(e.to_string());
}
Ok(_o) => {
return Ok(());
}
}
}
Thanks for the report !
This is fixed in 0.6.0
Currently the callback can only take fn pointers. I have an use case to pass the info onto a mpsc channel.
Let me know if there's another way to do it.
IIRC it should require a small change from
pub fn track_devices(&mut self, callback: fn(Device) -> Result<()>) -> Result<()> {
to
pub fn track_devices(&mut self, callback: impl Fn(Device) -> Result<()>) -> Result<()> {