1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
macro_rules! template {
($path:literal, $name:ident, $inner:ty) => {
#[derive(askama::Template)]
#[template(path = $path, escape = "none")]
pub struct $name<'a>(pub &'a $inner);
impl<'a> std::ops::Deref for $name<'a> {
type Target = $inner;
fn deref(&self) -> &$inner {
&self.0
}
}
};
}
macro_rules! template_module {
($name:ident, $backend:ty, [$namespace:literal, $struct:literal, $table:literal, $enum:literal, $union:literal, $rpc_service:literal]) => {
pub mod $name {
use crate::codegen::backend_translation::{
BackendDeclaration, BackendEnum, BackendNamespace, BackendRpcService,
BackendStruct, BackendTable, BackendTableFieldType, BackendUnion,
};
template!($namespace, Namespace, BackendNamespace<$backend>);
template!($struct, Struct, BackendStruct<$backend>);
template!($table, Table, BackendTable<$backend>);
template!($union, Union, BackendUnion<$backend>);
template!($enum, Enum, BackendEnum<$backend>);
template!($rpc_service, RpcService, BackendRpcService<$backend>);
}
};
}
template_module!(
rust,
crate::codegen::rust::RustBackend,
[
"rust/namespace.template",
"rust/struct.template",
"rust/table.template",
"rust/enum.template",
"rust/union.template",
"rust/rpc_service.template"
]
);