#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")]
mod cache;
pub(crate) mod compat;
#[doc(hidden)]
pub mod compiled;
pub mod consts;
mod context;
mod error;
mod filter;
mod frontmatter;
#[cfg(feature = "std")]
mod include;
mod include_core;
mod parser;
mod scope;
#[cfg(feature = "serde")]
mod serde_support;
mod template;
mod types;
mod value;
#[doc(hidden)]
pub mod __private {
pub use alloc::{borrow::Cow, boxed::Box, format, string::String, sync::Arc, vec, vec::Vec};
pub use crate::compat::LazyLock;
#[must_use]
pub fn fnv1a_hash(data: &[u8]) -> u64 {
const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
const FNV_PRIME: u64 = 0x0100_0000_01b3;
let mut hash = FNV_OFFSET;
for &byte in data {
hash ^= u64::from(byte);
hash = hash.wrapping_mul(FNV_PRIME);
}
hash
}
}
#[cfg(feature = "std")]
pub use cache::TemplateCache;
pub use context::Context;
pub use error::{SyntaxError, TemplateError};
#[doc(hidden)]
#[cfg(feature = "std")]
pub use frontmatter::parse_frontmatter_with_base_dir;
pub use frontmatter::{
Frontmatter, Import, ImportedNamespace, extract_template_stem, parse_frontmatter,
parse_frontmatter_with_env, parse_type_annotation, strip_frontmatter,
};
#[cfg(feature = "std")]
pub use frontmatter::{resolve_imports, resolve_imports_with_consts};
#[cfg(feature = "serde")]
pub use serde_support::{DeError, SerError, from_value, to_value};
#[cfg(feature = "std")]
pub use template::load_template;
pub use template::{CompileOptions, PrecompiledTemplateData, Template};
pub use types::{
BUILTIN_TYPE_NAMES, TypeCheckError, VarDecl, VarType, VariantDecl, to_pascal_case,
};
pub use value::{Value, ValueTypeError};
#[macro_export]
macro_rules! ctx {
($($key:ident : $val:tt),* $(,)?) => {{
let mut ctx = $crate::Context::with_capacity($crate::__count!($($key)*));
$(
ctx.set(stringify!($key), $crate::__value!($val));
)*
ctx
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __count {
() => { 0_usize };
($head:tt $($rest:tt)*) => { 1_usize + $crate::__count!($($rest)*) };
}
#[macro_export]
#[doc(hidden)]
macro_rules! __value {
([ $($item:tt),* $(,)? ]) => {
$crate::Value::List($crate::__private::Arc::new($crate::__private::vec![ $( $crate::__value!($item) ),* ]))
};
({ $($key:ident : $val:tt),* $(,)? }) => {
$crate::Value::new_struct([
$( (stringify!($key), $crate::__value!($val)) ),*
])
};
(( $e:expr )) => {
$crate::Value::from($e)
};
($other:expr) => {
$crate::Value::from($other)
};
}