home ~ projects ~ socials

Get A Vec Of Items From The args Passed Into A MiniJinja Env Function

- These are just scratch notes. They are just a placeholder until I can make a better example

- This is from sending spans in from Neopoligen teampltes

- They don't have good error handling (e.g. if you send something other than spans in, it breaks)

pub fn flatten_spans_in_template_v42(args: &[Value]) -> Result<Value, Error> {
    if args.len() == 1 {
        let x: &String = &args[0]
            .try_iter()?
            .map(|v| v.get_item(&Value::from("text")).unwrap().to_string())
            .collect::<Vec<_>>()
            .join("");
        Ok(Value::from(x))
    } else {
        Err(Error::new(
            ErrorKind::InvalidOperation,
            "Missing argument for flatten_spans in template".to_string(),
        ))
    }
}
-- end of line --