76d7671c8a
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>
29 lines
737 B
Rust
29 lines
737 B
Rust
pub use tvix_eval::internal;
|
|
pub use tvix_eval::Value;
|
|
use tvix_eval_builtin_macros::builtins;
|
|
|
|
#[builtins]
|
|
mod builtins {
|
|
use tvix_eval::internal::VM;
|
|
use tvix_eval::{ErrorKind, Value};
|
|
|
|
/// Test docstring
|
|
#[builtin("identity")]
|
|
pub fn builtin_identity(_vm: &mut VM, x: Value) -> Result<Value, ErrorKind> {
|
|
Ok(x)
|
|
}
|
|
|
|
#[builtin("tryEval")]
|
|
pub fn builtin_try_eval(_: &mut VM, #[lazy] _x: Value) -> Result<Value, ErrorKind> {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn builtins() {
|
|
let builtins = builtins::builtins();
|
|
assert_eq!(builtins.len(), 2);
|
|
|
|
let identity = builtins.iter().find(|b| b.name() == "identity").unwrap();
|
|
assert_eq!(identity.documentation(), Some(" Test docstring"));
|
|
}
|