use std::borrow::Cow; use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use crate::util::elisp_fact::ElispFact; use crate::types::LinkType; use crate::types::RegularLink; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] #[serde(tag = "format")] #[serde(rename = "bracket")] pub struct WasmRegularLink { #[serde(rename = "type")] pub(crate) link_type: String, pub(crate) path: String, #[serde(rename = "raw-link")] pub(crate) raw_link: String, pub(crate) application: Option, #[serde(rename = "search-option")] pub(crate) search_option: Option, } to_wasm!( WasmRegularLink, RegularLink<'s>, original, wasm_context, { WasmAstNode::RegularLink(original) }, { "link".into() }, { let children = original .children .iter() .map(|child| { child .to_wasm(wasm_context.clone()) .map(Into::::into) }) .collect::, _>>()?; Ok(( children, WasmRegularLink { link_type: match &original.link_type { LinkType::File => "file".to_owned(), LinkType::Protocol(protocol) => protocol.clone().into_owned(), LinkType::Id => "id".to_owned(), LinkType::CustomId => "custom-id".to_owned(), LinkType::CodeRef => "coderef".to_owned(), LinkType::Fuzzy => "fuzzy".to_owned(), }, path: original.get_path().into_owned(), raw_link: original.get_raw_link().into_owned(), application: original .application .as_ref() .map(|c| c.clone().into_owned()), search_option: original.get_search_option().map(Cow::into_owned), }, )) } );