use std::borrow::Cow; use mlua::{IntoLua, Lua, Value}; use serde::{Deserialize, Serialize}; use yazi_shared::url::Url; use super::Ember; #[derive(Debug, Serialize, Deserialize)] pub struct EmberMove<'a> { pub items: Cow<'a, Vec>, } impl<'a> EmberMove<'a> { pub fn borrowed(items: &'a Vec) -> Ember<'a> { Self { items: Cow::Borrowed(items) }.into() } } impl EmberMove<'static> { pub fn owned(items: Vec) -> Ember<'static> { Self { items: Cow::Owned(items) }.into() } } impl<'a> From> for Ember<'a> { fn from(value: EmberMove<'a>) -> Self { Self::Move(value) } } impl IntoLua for EmberMove<'_> { fn into_lua(self, lua: &Lua) -> mlua::Result { lua.create_table_from([("items", self.items.into_owned())])?.into_lua(lua) } } // --- Item #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BodyMoveItem { pub from: Url, pub to: Url, } impl IntoLua for BodyMoveItem { fn into_lua(self, lua: &Lua) -> mlua::Result { lua .create_table_from([ ("from", yazi_binding::Url::new(self.from)), ("to", yazi_binding::Url::new(self.to)), ])? .into_lua(lua) } }