Skip to main content

mailang_stdlib/stdlib/
string.rs

1//! String built-in functions
2
3use mailang_bytecode::Value;
4
5pub fn builtin_len(args: &[Value]) -> Result<Value, String> {
6    match &args[0] {
7        Value::Str(s) => Ok(Value::Int(s.chars().count() as i64)),
8        Value::Array(a) => Ok(Value::Int(a.borrow().len() as i64)),
9        Value::Map(m) => Ok(Value::Int(m.borrow().len() as i64)),
10        Value::Tuple(t) => Ok(Value::Int(t.borrow().len() as i64)),
11        _ => Err("len expects a string, array, map, or tuple".to_string()),
12    }
13}