mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
24 lines
629 B
Rust
24 lines
629 B
Rust
use mlua::{IntoLuaMulti, UserData, UserDataMethods, Value};
|
|
|
|
use crate::Error;
|
|
|
|
pub enum SizeCalculator {
|
|
Local(yazi_fs::provider::local::SizeCalculator),
|
|
Remote(yazi_vfs::provider::SizeCalculator),
|
|
}
|
|
|
|
impl UserData for SizeCalculator {
|
|
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
|
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
|
let next = match &mut *me {
|
|
Self::Local(it) => it.next().await,
|
|
Self::Remote(it) => it.next().await,
|
|
};
|
|
|
|
match next {
|
|
Ok(value) => value.into_lua_multi(&lua),
|
|
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua),
|
|
}
|
|
});
|
|
}
|
|
}
|