home ~ projects ~ socials

Get A Vec Of Child Objects In MiniJinja

```cargo
[dependencies]
minijinja = "2.0.1"
```

use minijinja::value::{Object, Value};
use minijinja::{context, Environment, Error};
use std::fmt::Display;
use std::sync::Arc;

fn main() {
  let mut env = Environment::new();
  println!("eeeee");
}

pub sturct Alfa {
  items: Vec<Bravo>
}

pub struct Bravo {}

impl Alfa {
  pub fn get_items(&self) -> Result<Vec<Value>> {
  }
}

impl Object for Alfa {
    fn call_method(
       self: &Arc<Alfa>,
        _state: &minijinja::State,
        name: &str,
        _args: &[Value],
    ) -> Result<Value, Error> {
        match name {
            "ping" => Ok(Value::from(self.ping())),
            _ => Ok(Value::from(""))
        }
    }
}


impl Display for Alfa {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "alfa")
    }
}

impl Object for Bravo {
    fn call_method(
       self: &Arc<Bravo>,
        _state: &minijinja::State,
        name: &str,
        _args: &[Value],
    ) -> Result<Value, Error> {
        match name {
            "ping" => Ok(Value::from(self.ping())),
            _ => Ok(Value::from(""))
        }
    }
}

impl Display for Bravo {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "alfa")
    }
}
Output:
eeeee

warning: unused imports: `Object`, `Value`
 --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:6:24
  |
6 | use minijinja::value::{Object, Value};
  |                        ^^^^^^  ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused imports: `Error`, `context`
 --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:7:17
  |
7 | use minijinja::{context, Environment, Error};
  |                 ^^^^^^^               ^^^^^

warning: unused import: `std::fmt::Display`
 --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:8:5
  |
8 | use std::fmt::Display;
  |     ^^^^^^^^^^^^^^^^^

warning: unused import: `std::sync::Arc`
 --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:9:5
  |
9 | use std::sync::Arc;
  |     ^^^^^^^^^^^^^^

warning: unused variable: `env`
  --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:12:11
   |
12 |   let mut env = Environment::new();
   |           ^^^ help: if this is intentional, prefix it with an underscore: `_env`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> /Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:12:7
   |
12 |   let mut env = Environment::new();
   |       ----^^^
   |       |
   |       help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default
-- end of line --