Skip to main content

TModel

Struct TModel 

Source
pub struct TModel {
Show 22 fields pub scalar: Option<Rc<dyn TemplateScalarModel>>, pub number: Option<ModelNumber>, pub boolean: Option<Rc<dyn TemplateBooleanModel>>, pub date: Option<Rc<dyn TemplateDateModel>>, pub sequence: Option<Rc<dyn TemplateSequenceModel>>, pub collection: Option<Rc<dyn TemplateCollectionModel>>, pub hash: Option<Rc<dyn TemplateHashModel>>, pub hash_ex: Option<Rc<dyn TemplateHashModelEx>>, pub method: Option<Rc<dyn TemplateMethodModelEx>>, pub method_indexable: bool, pub collection_ex: bool, pub directive: Option<Rc<dyn TemplateDirectiveModel>>, pub transform: Option<Rc<dyn TemplateTransformModel>>, pub range: Option<Rc<RangeSpec>>, pub node: Option<Rc<dyn TemplateNodeModel>>, pub node_hash: Option<Rc<dyn NodeHashModel>>, pub api: Option<Rc<dyn TemplateApiSupport>>, pub internal: Option<Rc<dyn Any>>, pub markup_format: Option<OutputFormatKind>, pub markup_plain: Option<String>, pub type_name: &'static str, pub kind: ModelKind,
}
Expand description

模板模型:每个槽位对应一个角色 trait(可多角色,如 Python 通用模型)

Fields§

§scalar: Option<Rc<dyn TemplateScalarModel>>§number: Option<ModelNumber>§boolean: Option<Rc<dyn TemplateBooleanModel>>§date: Option<Rc<dyn TemplateDateModel>>§sequence: Option<Rc<dyn TemplateSequenceModel>>§collection: Option<Rc<dyn TemplateCollectionModel>>§hash: Option<Rc<dyn TemplateHashModel>>§hash_ex: Option<Rc<dyn TemplateHashModelEx>>§method: Option<Rc<dyn TemplateMethodModelEx>>§method_indexable: bool

方法模型的可索引性 —— 对应 Java BeansWrapper 的 GenericMethodModel 实现 TemplateSequenceModel(?is_indexable → true;?is_sequence 在 ICI ≥ 2.3.24 仍排除——不可 #list)。自定义方法模型(TemplateMethodModelEx 匿名类)不实现 TemplateSequenceModel → false。

§collection_ex: bool

集合的 Ex 角色 —— 对应 Java TemplateCollectionModelEx(?is_collection_ex)。 SimpleSequence 实现 Ex;SimpleCollection 不实现(SimpleCollection.java:41-42)。

§directive: Option<Rc<dyn TemplateDirectiveModel>>§transform: Option<Rc<dyn TemplateTransformModel>>

变换模型角色(对应 Java TemplateTransformModel;<#transform> 目标)

§range: Option<Rc<RangeSpec>>

范围模型标记(对应 Java RangeModel;seq[range] 切片键类型判定)

§node: Option<Rc<dyn TemplateNodeModel>>§node_hash: Option<Rc<dyn NodeHashModel>>

节点哈希角色(对应 Java NodeModel 的 TemplateHashModel;doc.foo/doc['//x'] 访问)。 与 hash 槽位分开:get 需要 Environment 解析 ns_prefixes(Java 线程局部 Environment;Rust 显式传参,见 template_model.rs NodeHashModel 注释)。

§api: Option<Rc<dyn TemplateApiSupport>>

API 支持槽位(对应 Java TemplateModelWithAPISupport;?api/?has_api)。 引擎自身不支持反射,由包装方(对象包装器)提供 API 视图。

§internal: Option<Rc<dyn Any>>

内部扩展槽位(渲染引擎专用,docs/04 §1):承载宏/函数值、lambda、命名空间等 Rust 特有设计(Java 中这些是 TemplateModel 实现类,Rust 侧统一用 Any 下沉)。

§markup_format: Option<OutputFormatKind>

markup 输出的创建时输出格式(对应 Java TemplateMarkupOutputModel.getOutputFormat / CommonTemplateMarkupOutputModel;kind == Markup 时非 None)

§markup_plain: Option<String>

markup 输出的源纯文本(Java CommonTemplateMarkupOutputModel.getPlainTextContent; ?esc 产物 = 原始文本;?no_esc/块捕获(fromMarkup)产物 = None —— 跨格式转换不可逆时插值报错,见 DollarVariable.java:78-92)

§type_name: &'static str

用户可见的类型描述(错误消息 has evaluated to a {actual} 使用)

§kind: ModelKind

Implementations§

Source§

impl TModel

Source

pub fn nothing() -> TModel

Source

pub fn gpn() -> TModel

?if_exists 的缺失结果 —— 对应 Java TemplateModel.NOTHING (GeneralPurposeNothing.java:全能空角色模型——scalar “”、boolean false、 空序列、空哈希、方法返回 null)。与真缺失(Java null → TModel::nothing()) 不同:任何使用点按“最合理方式“解释(插值 → “”、布尔 → false、 序列/哈希 → 空),不触发 InvalidReference。

Source

pub fn from_scalar(v: String) -> TModel

Source

pub fn from_number(v: TNumber) -> TModel

Source

pub fn from_boolean(b: bool) -> TModel

Source

pub fn from_date(d: DateValue) -> TModel

Source

pub fn from_sequence(v: Vec<TModel>) -> TModel

Source

pub fn from_collection(v: Vec<TModel>) -> TModel

一次性集合(仅 Collection 角色,无 Sequence 角色)—— 对应 Java SimpleCollection (只实现 TemplateCollectionModel,无 Ex:?is_collection_ex → false)。 注意与 from_sequence 的区别:只能枚举一次(iterator 消费语义,docs/06 §2)。

Source

pub fn from_hash(v: IndexMap<String, TModel>) -> TModel

Source

pub fn from_method(m: impl TemplateMethodModelEx + 'static) -> TModel

Source

pub fn from_directive(d: impl TemplateDirectiveModel + 'static) -> TModel

Source

pub fn from_transform(t: impl TemplateTransformModel + 'static) -> TModel

Source

pub fn from_xml_str(s: &str) -> Result<TModel>

从 XML 文本构造文档节点模型 —— 对应 Java NodeModel.parse(InputSource) (freemarker.ext.dom:SAX 解析 → simplify —— 移除注释/PI、合并相邻文本)。 返回“document“节点;子节点经 ?children / 哈希键访问导航。

Source

pub fn is_scalar(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_boolean(&self) -> bool

Source

pub fn is_date(&self) -> bool

Source

pub fn is_sequence(&self) -> bool

Source

pub fn is_collection(&self) -> bool

Source

pub fn is_hash(&self) -> bool

Source

pub fn is_hash_ex(&self) -> bool

Source

pub fn is_method(&self) -> bool

Source

pub fn is_directive(&self) -> bool

Source

pub fn is_node(&self) -> bool

Source

pub fn is_nothing(&self) -> bool

Source

pub fn is_enumerable(&self) -> bool

对应 Java instanceof TemplateSequenceModel || TemplateCollectionModel(?is_enumerable)

Source

pub fn is_collection_ex(&self) -> bool

对应 Java instanceof TemplateCollectionModelEx(?is_collection_ex)—— 由 collection_ex 标记承载(SimpleSequence 是 Ex,SimpleCollection 不是)

Source

pub fn has_api(&self) -> bool

对应 Java instanceof TemplateModelWithAPISupport(?has_api;Rust 版不支持 → false)

Source

pub fn is_transform(&self) -> bool

对应 Java instanceof TemplateTransformModel(?is_transform;?interpret 产物)

Source

pub fn is_markup_output(&self) -> bool

对应 Java instanceof TemplateMarkupOutputModel(?is_markup_output)

Source

pub fn is_macro(&self) -> bool

对应 Java instanceof TemplateMacroModel(?is_macro;宏/函数值由渲染引擎构造, 对应 Java Macro 对象——docs/04 §6)

Source

pub fn is_lambda(&self) -> bool

对应 Java LocalLambdaExpression 求值结果(?is_callable 家族;v1 仅存槽位)

Source

pub fn internal<T: 'static>(&self) -> Option<Rc<T>>

取内部扩展槽位(渲染引擎专用;对应 Java 中无法用 FTL 接口表达的模型值)

Source

pub fn get_scalar(&self) -> Result<String>

Source

pub fn get_number(&self) -> Result<TNumber>

Source

pub fn get_boolean(&self) -> Result<bool>

Source

pub fn get_date(&self) -> Result<DateValue>

Source

pub fn get_sequence(&self) -> Result<Rc<dyn TemplateSequenceModel>>

Source

pub fn get_hash(&self) -> Result<Rc<dyn TemplateHashModel>>

Source

pub fn get_method(&self) -> Result<Rc<dyn TemplateMethodModelEx>>

Source

pub fn get_directive(&self) -> Result<Rc<dyn TemplateDirectiveModel>>

Source

pub fn get_transform(&self) -> Result<Rc<dyn TemplateTransformModel>>

Source

pub fn is_null_or_missing(&self) -> bool

缺失语义:Nothing 视为 null(?has_content 判空、${x!} 抑制)

Source

pub fn has_content(&self) -> Result<bool>

空值判定(?has_content 内建:标量空串 / 空序列 / 空哈希)

Source

pub fn eval_boolean(&self) -> Result<bool>

布尔值求值(<#if x> 语义;非布尔抛 NonBooleanException)

Trait Implementations§

Source§

impl Clone for TModel

Source§

fn clone(&self) -> TModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for TModel

§

impl !Send for TModel

§

impl !Sync for TModel

§

impl !UnwindSafe for TModel

§

impl Freeze for TModel

§

impl Unpin for TModel

§

impl UnsafeUnpin for TModel

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.