summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-20 16:08:16 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-20 16:11:37 +0100
commitf5f7df7247ae29800e0290774a50942e2485beea (patch)
tree57253ba51efdae3ac8e4eea722428924625b514c /src/model
parentb8ffd3ad3dcaebddbc674e03494e0d818b21fa51 (diff)
Documentation
Diffstat (limited to 'src/model')
-rw-r--r--src/model/eval.rs11
-rw-r--r--src/model/func.rs17
2 files changed, 9 insertions, 19 deletions
diff --git a/src/model/eval.rs b/src/model/eval.rs
index 91fe61bb..a9fa2e14 100644
--- a/src/model/eval.rs
+++ b/src/model/eval.rs
@@ -476,10 +476,7 @@ impl Eval for ast::Frac {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok((vm.items.math_frac)(
- self.num().eval(vm)?,
- self.denom().eval(vm)?,
- ))
+ Ok((vm.items.math_frac)(self.num().eval(vm)?, self.denom().eval(vm)?))
}
}
@@ -781,11 +778,7 @@ impl Eval for ast::FieldAccess {
.field(&field)
.ok_or_else(|| format!("unknown field {field:?}"))
.at(span)?,
- v => bail!(
- self.target().span(),
- "cannot access field on {}",
- v.type_name()
- ),
+ v => bail!(self.target().span(), "cannot access field on {}", v.type_name()),
})
}
}
diff --git a/src/model/func.rs b/src/model/func.rs
index fb8b3dd0..e47594a1 100644
--- a/src/model/func.rs
+++ b/src/model/func.rs
@@ -37,18 +37,16 @@ impl Func {
/// Create a new function from a native rust function.
pub fn from_fn(
- name: &'static str,
func: fn(&Vm, &mut Args) -> SourceResult<Value>,
info: FuncInfo,
) -> Self {
- Self(Arc::new(Repr::Native(Native { name, func, set: None, node: None, info })))
+ Self(Arc::new(Repr::Native(Native { func, set: None, node: None, info })))
}
/// Create a new function from a native rust node.
- pub fn from_node<T: Node>(name: &'static str, mut info: FuncInfo) -> Self {
+ pub fn from_node<T: Node>(mut info: FuncInfo) -> Self {
info.params.extend(T::properties());
Self(Arc::new(Repr::Native(Native {
- name,
func: |ctx, args| {
let styles = T::set(args, true)?;
let content = T::construct(ctx, args)?;
@@ -68,7 +66,7 @@ impl Func {
/// The name of the function.
pub fn name(&self) -> Option<&str> {
match self.0.as_ref() {
- Repr::Native(native) => Some(native.name),
+ Repr::Native(native) => Some(native.info.name),
Repr::Closure(closure) => closure.name.as_deref(),
Repr::With(func, _) => func.name(),
}
@@ -184,8 +182,6 @@ pub trait FuncType {
/// A function defined by a native rust function or node.
struct Native {
- /// The name of the function.
- name: &'static str,
/// The function pointer.
func: fn(&Vm, &mut Args) -> SourceResult<Value>,
/// The set rule.
@@ -198,7 +194,6 @@ struct Native {
impl Hash for Native {
fn hash<H: Hasher>(&self, state: &mut H) {
- self.name.hash(state);
(self.func as usize).hash(state);
self.set.map(|set| set as usize).hash(state);
self.node.hash(state);
@@ -210,8 +205,10 @@ impl Hash for Native {
pub struct FuncInfo {
/// The function's name.
pub name: &'static str,
- /// Tags that categorize the function.
- pub tags: &'static [&'static str],
+ /// The display name of the function.
+ pub display: &'static str,
+ /// Which category the function is part of.
+ pub category: &'static str,
/// Documentation for the function.
pub docs: &'static str,
/// The source code of an example, if any.