use std::sync::Arc;
use indexmap::IndexMap;
use crate::context::IExpressionContext;
use crate::exceptions::TemplateProcessingException;
use crate::expression::TemplateValue;
use crate::util::Utf16String;
use super::ILinkBuilder;
pub struct AbstractLinkBuilder<F> {
name: Option<Utf16String>,
order: Option<i32>,
build_link: F,
}
impl<F> AbstractLinkBuilder<F> {
pub fn new(class_name: &'static str, build_link: F) -> Self {
Self {
name: Some(Utf16String::from_rust_str(class_name)),
order: None,
build_link,
}
}
#[must_use]
pub const fn get_name(&self) -> Option<&Utf16String> {
self.name.as_ref()
}
pub fn set_name(&mut self, name: Option<Utf16String>) {
self.name = name;
}
#[must_use]
pub const fn get_order(&self) -> Option<i32> {
self.order
}
pub fn set_order(&mut self, order: Option<i32>) {
self.order = order;
}
}
impl<F> ILinkBuilder for AbstractLinkBuilder<F>
where
F: Fn(
&dyn IExpressionContext,
Option<&Utf16String>,
Option<&IndexMap<Option<Utf16String>, Option<Arc<TemplateValue>>>>,
) -> Result<Option<Utf16String>, TemplateProcessingException>
+ Send
+ Sync,
{
fn get_name(&self) -> Option<&Utf16String> {
self.get_name()
}
fn get_order(&self) -> Option<i32> {
self.get_order()
}
fn build_link(
&self,
context: &dyn IExpressionContext,
base: Option<&Utf16String>,
parameters: Option<&IndexMap<Option<Utf16String>, Option<Arc<TemplateValue>>>>,
) -> Result<Option<Utf16String>, TemplateProcessingException> {
(self.build_link)(context, base, parameters)
}
}