Files
organic/src/wasm/citation.rs

72 lines
1.9 KiB
Rust
Raw Normal View History

use serde::Deserialize;
use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use crate::compare::ElispFact;
use crate::types::Citation;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
2023-12-29 12:49:43 -05:00
pub struct WasmCitation {
2023-12-30 16:33:02 -05:00
pub(crate) style: Option<String>,
pub(crate) prefix: Option<Vec<WasmAstNode>>,
pub(crate) suffix: Option<Vec<WasmAstNode>>,
}
to_wasm!(
2023-12-29 12:49:43 -05:00
WasmCitation,
2023-12-25 11:51:39 -05:00
Citation<'s>,
2023-12-25 12:32:35 -05:00
original,
wasm_context,
{ WasmAstNode::Citation(original) },
2023-12-30 16:33:02 -05:00
{ "citation".into() },
{
let children = original
.children
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
2023-12-30 16:33:02 -05:00
let prefix = original
.prefix
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
let suffix = original
.suffix
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?;
Ok((
children,
WasmCitation {
2023-12-30 16:33:02 -05:00
style: original.style.map(|s| s.to_owned()),
prefix: if prefix.is_empty() {
None
} else {
Some(prefix)
},
suffix: if suffix.is_empty() {
None
} else {
Some(suffix)
},
},
))
}
);