feat: rec attrset

This commit is contained in:
2025-08-08 12:12:23 +08:00
parent 67cdcfea33
commit a9cfddbf5c
13 changed files with 147 additions and 180 deletions

View File

@@ -27,11 +27,28 @@ pub mod builtins {
})
}
pub fn import<Ctx: BuiltinsContext>(ctx: &mut Ctx, path: Value) -> Result<Value> {
pub fn import(ctx: &mut impl BuiltinsContext, path: Value) -> Result<Value> {
todo!()
}
fn elem_at(list: Value, idx: Value) -> Result<Value> {
let list = list
.try_unwrap_list()
.map_err(|_| Error::EvalError("expected a list but found ...".to_string()))?;
let idx = idx
.try_unwrap_int()
.map_err(|_| Error::EvalError("expected a int but found ...".to_string()))?;
list.get(idx as usize)
.ok_or_else(|| {
Error::EvalError(format!(
"'builtins.elemAt' called with index {idx} on a list of size {}",
list.len()
))
})
.cloned()
}
fn elem(elem: Value, list: Value) -> Result<Value> {
todo!()
}
}