Files
natter/src/context/macros.rs
2025-02-08 18:37:32 -05:00

58 lines
1.5 KiB
Rust

/// Write the implementation for the render ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! render {
($rstruct:ident, $istruct:ident, $original:ident, $render_context:ident, $fnbody:tt) => {
impl $rstruct {
pub(crate) fn new(
$render_context: RenderContext<'_>,
$original: &$istruct,
) -> Result<$rstruct, CustomError> {
$fnbody
}
}
};
}
pub(crate) use render;
/// Write the implementation for a render ast node that has no fields.
///
/// This exists to make changing the type signature easier.
macro_rules! rnoop {
($rstruct:ident, $istruct:ident) => {
impl $rstruct {
pub(crate) fn new(
_render_context: RenderContext<'_>,
original: &$istruct,
) -> Result<$rstruct, CustomError> {
Ok($rstruct {
post_blank: original.post_blank,
})
}
}
};
}
pub(crate) use rnoop;
/// Push a file onto the render DependencyManager's file stack while inside the code block.
macro_rules! push_file {
($render_context:ident, $path:expr, $body:tt) => {{
$render_context
.dependency_manager
.lock()
.unwrap()
.push_file($path)?;
let ret = (|| $body)();
$render_context
.dependency_manager
.lock()
.unwrap()
.pop_file()?;
ret
}};
}
pub(crate) use push_file;