use tokio::sync::mpsc; use tracing::error; use yazi_shared::event::Cmd; use crate::which::Which; pub struct Opt { tx: mpsc::Sender, idx: usize, } impl TryFrom for Opt { type Error = (); fn try_from(mut c: Cmd) -> Result { Ok(Self { tx: c.take_any("tx").ok_or(())?, idx: c.take_first_str().and_then(|s| s.parse().ok()).ok_or(())?, }) } } impl Which { pub fn callback(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { return; }; if opt.tx.try_send(opt.idx).is_err() { error!("which callback: send error"); } } }