use super::{TLinkType, TLinkage};
use crate::language::Term;
pub type TermLinkTemplate = TLinkage<Term>;
impl TermLinkTemplate {
pub fn new_template(target: Term, link_type: TLinkType, index: impl Into<Vec<usize>>) -> Self {
Self::new_direct(
target,
link_type,
Self::generate_template_indexes(link_type, index),
)
}
fn generate_template_indexes(
link_type: TLinkType,
indexes: impl Into<Vec<usize>>,
) -> Box<[usize]> {
debug_assert!(
link_type.is_to_compound() || link_type == TLinkType::Transform,
"链接类型 {link_type:?} 并非链接到复合词项"
);
let mut index = indexes.into();
if link_type == TLinkType::CompoundCondition {
index.insert(0, 0);
}
index.into_boxed_slice()
}
}