2023-12-30 12:14:03 -05:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
use serde::Deserialize;
|
2023-12-25 11:33:43 -05:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
use super::ast_node::WasmAstNode;
|
2023-12-25 11:33:43 -05:00
|
|
|
use super::macros::to_wasm;
|
|
|
|
|
use super::to_wasm::ToWasm;
|
2023-12-29 15:03:36 -05:00
|
|
|
use crate::compare::ElispFact;
|
2023-12-30 12:14:03 -05:00
|
|
|
use crate::types::LinkType;
|
2023-12-27 11:36:47 -05:00
|
|
|
use crate::types::RegularLink;
|
2023-12-25 11:33:43 -05:00
|
|
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
|
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-12-30 12:14:03 -05:00
|
|
|
#[serde(tag = "format")]
|
|
|
|
|
#[serde(rename = "bracket")]
|
2023-12-29 12:49:43 -05:00
|
|
|
pub struct WasmRegularLink {
|
2023-12-30 12:14:03 -05:00
|
|
|
#[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<String>,
|
|
|
|
|
#[serde(rename = "search-option")]
|
|
|
|
|
pub(crate) search_option: Option<String>,
|
2023-12-25 11:33:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to_wasm!(
|
2023-12-29 12:49:43 -05:00
|
|
|
WasmRegularLink,
|
2023-12-25 11:51:39 -05:00
|
|
|
RegularLink<'s>,
|
2023-12-25 12:32:35 -05:00
|
|
|
original,
|
2023-12-25 11:33:43 -05:00
|
|
|
wasm_context,
|
2023-12-29 15:03:36 -05:00
|
|
|
{ WasmAstNode::RegularLink(original) },
|
2023-12-30 12:14:03 -05:00
|
|
|
{ "link".into() },
|
2023-12-25 11:33:43 -05:00
|
|
|
{
|
2023-12-29 15:03:36 -05:00
|
|
|
let children = original
|
|
|
|
|
.children
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|child| {
|
|
|
|
|
child
|
|
|
|
|
.to_wasm(wasm_context.clone())
|
|
|
|
|
.map(Into::<WasmAstNode>::into)
|
|
|
|
|
})
|
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
2023-12-27 19:53:07 -05:00
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
Ok((
|
|
|
|
|
children,
|
|
|
|
|
WasmRegularLink {
|
2023-12-30 12:14:03 -05:00
|
|
|
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),
|
2023-12-29 15:03:36 -05:00
|
|
|
},
|
|
|
|
|
))
|
2023-12-27 19:53:07 -05:00
|
|
|
}
|
2023-12-29 15:03:36 -05:00
|
|
|
);
|