feat(tvix/eval): Add docstrings as documentation for builtins
Add a new `documentation: Option<&'static str>` field to Builtin, and populate it in the `#[builtins]` macro with the docstring of the builtin function, if any. Change-Id: Ic68fdf9b314d15a780731974234e2ae43f6a44b0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7205 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
a1015ba1d7
commit
76d7671c8a
5 changed files with 54 additions and 2 deletions
|
|
@ -50,6 +50,8 @@ pub struct Builtin {
|
|||
name: &'static str,
|
||||
/// Array of arguments to the builtin.
|
||||
arguments: &'static [BuiltinArgument],
|
||||
/// Optional documentation for the builtin.
|
||||
documentation: Option<&'static str>,
|
||||
func: Rc<dyn BuiltinFn>,
|
||||
|
||||
/// Partially applied function arguments.
|
||||
|
|
@ -60,11 +62,13 @@ impl Builtin {
|
|||
pub fn new<F: BuiltinFn + 'static>(
|
||||
name: &'static str,
|
||||
arguments: &'static [BuiltinArgument],
|
||||
documentation: Option<&'static str>,
|
||||
func: F,
|
||||
) -> Self {
|
||||
Builtin {
|
||||
name,
|
||||
arguments,
|
||||
documentation,
|
||||
func: Rc::new(func),
|
||||
partials: vec![],
|
||||
}
|
||||
|
|
@ -74,6 +78,10 @@ impl Builtin {
|
|||
self.name
|
||||
}
|
||||
|
||||
pub fn documentation(&self) -> Option<&'static str> {
|
||||
self.documentation
|
||||
}
|
||||
|
||||
/// Apply an additional argument to the builtin, which will either
|
||||
/// lead to execution of the function or to returning a partial
|
||||
/// builtin.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue