Implement a new to_wasm macro that uses the WasmAstNodeWrapper.

This commit is contained in:
Tom Alexander
2023-12-29 14:06:10 -05:00
parent a0a4f0eb90
commit cad2be43bf
3 changed files with 86 additions and 55 deletions

View File

@@ -5,8 +5,8 @@ use serde::Serialize;
use super::additional_property::AdditionalProperties;
use super::additional_property::AdditionalPropertyValue;
use super::ast_node::WasmAstNode;
use super::macros::new_to_wasm;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
#[cfg(feature = "wasm_test")]
use crate::compare::ElispFact;
@@ -14,26 +14,21 @@ use crate::types::Document;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize)]
#[serde(tag = "__ast_node")]
#[serde(rename = "org-data")]
pub struct WasmDocument {
#[serde(rename = "standard-properties")]
pub(crate) standard_properties: WasmStandardProperties,
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
#[serde(rename = "__children")]
pub(crate) children: Vec<WasmAstNode>,
#[serde(rename = "CATEGORY")]
pub(crate) category: Option<String>,
pub(crate) path: Option<PathBuf>,
}
to_wasm!(
new_to_wasm!(
WasmDocument,
Document<'s>,
original,
wasm_context,
standard_properties,
{ WasmAstNode::Document(original) },
{ "org-data".into() },
{
let category = original.category.as_ref().map(String::as_str);
let path = original.path.clone();
@@ -63,25 +58,13 @@ to_wasm!(
}))
.collect::<Result<Vec<_>, _>>()?;
Ok(WasmDocument {
standard_properties,
additional_properties,
Ok((
children,
category: category.map(str::to_owned),
path,
})
WasmDocument {
additional_properties,
category: category.map(str::to_owned),
path,
},
))
}
);
impl Into<WasmAstNode> for WasmDocument {
fn into(self) -> WasmAstNode {
WasmAstNode::Document(self)
}
}
#[cfg(feature = "wasm_test")]
impl<'s> ElispFact<'s> for WasmDocument {
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
"org-data".into()
}
}