use std::sync::{Arc, OnceLock};
use crate::context::ITemplateContext;
use crate::expression::StandardExpressionResult;
use crate::model::{ICDATASection, IComment, IText};
use crate::util::{CharSequenceValue, Utf16String};
use super::IInliner;
static NO_OP_INLINER: OnceLock<Arc<NoOpInliner>> = OnceLock::new();
#[non_exhaustive]
pub struct NoOpInliner;
impl NoOpInliner {
#[must_use]
pub fn instance() -> &'static Self {
concrete_instance().as_ref()
}
#[must_use]
pub fn shared() -> Arc<dyn IInliner> {
Arc::<NoOpInliner>::clone(concrete_instance())
}
pub fn inline_text_nullable(
&self,
_context: Option<&dyn ITemplateContext>,
_text: Option<&dyn IText>,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
Ok(None)
}
pub fn inline_cdata_section_nullable(
&self,
_context: Option<&dyn ITemplateContext>,
_cdata_section: Option<&dyn ICDATASection>,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
Ok(None)
}
pub fn inline_comment_nullable(
&self,
_context: Option<&dyn ITemplateContext>,
_comment: Option<&dyn IComment>,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
Ok(None)
}
}
fn concrete_instance() -> &'static Arc<NoOpInliner> {
NO_OP_INLINER.get_or_init(|| Arc::new(NoOpInliner))
}
impl IInliner for NoOpInliner {
fn get_name(&self) -> &Utf16String {
static NAME: OnceLock<Utf16String> = OnceLock::new();
NAME.get_or_init(|| Utf16String::from_rust_str("NOOP"))
}
fn inline_text(
&self,
context: &dyn ITemplateContext,
text: &dyn IText,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
self.inline_text_nullable(Some(context), Some(text))
}
fn inline_cdata_section(
&self,
context: &dyn ITemplateContext,
cdata_section: &dyn ICDATASection,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
self.inline_cdata_section_nullable(Some(context), Some(cdata_section))
}
fn inline_comment(
&self,
context: &dyn ITemplateContext,
comment: &dyn IComment,
) -> StandardExpressionResult<Option<Box<dyn CharSequenceValue>>> {
self.inline_comment_nullable(Some(context), Some(comment))
}
}