use std::borrow::Cow; use hashbrown::HashMap; use mlua::{IntoLua, Lua, Value}; use serde::{Deserialize, Serialize}; use yazi_shared::url::UrlBuf; use super::Ember; #[derive(Debug, Deserialize, Serialize)] pub struct EmberBulk<'a> { pub changes: HashMap, Cow<'a, UrlBuf>>, } impl<'a> EmberBulk<'a> { pub fn borrowed(changes: I) -> Ember<'a> where I: Iterator, { Self { changes: changes.map(|(from, to)| (from.into(), to.into())).collect() }.into() } } impl EmberBulk<'static> { pub fn owned<'a, I>(changes: I) -> Ember<'static> where I: Iterator, { Self { changes: changes.map(|(from, to)| (from.clone().into(), to.clone().into())).collect() } .into() } } impl<'a> From> for Ember<'a> { fn from(value: EmberBulk<'a>) -> Self { Self::Bulk(value) } } impl IntoLua for EmberBulk<'_> { fn into_lua(self, lua: &Lua) -> mlua::Result { lua .create_table_from( self .changes .into_iter() .map(|(from, to)| (yazi_binding::Url::new(from), yazi_binding::Url::new(to))), )? .into_lua(lua) } }