1use rhai::plugin::*;
2
3#[export_module]
4pub mod set_functions {
5 use rhai::{Array, EvalAltResult};
6
7 #[rhai_fn(name = "union", return_raw)]
15 pub fn union(arr1: Array, arr2: Array) -> Result<Array, Box<EvalAltResult>> {
16 let mut x = arr1.clone();
17 let y = arr2.clone();
18 x.extend(y);
19 crate::misc_functions::unique(&mut x)
20 }
21
22 #[rhai_fn(name = "intersect", return_raw)]
30 pub fn intersect(arr1: Array, arr2: Array) -> Result<Array, Box<EvalAltResult>> {
31 let array2 = arr2
32 .into_iter()
33 .map(|x| format!("{:?}", x).to_string())
34 .collect::<Vec<String>>();
35 let mut new_arr = vec![];
36 for el in arr1 {
37 if array2.contains(&format!("{:?}", el).to_string()) {
38 new_arr.push(el);
39 }
40 }
41 Ok(crate::misc_functions::unique(&mut new_arr).unwrap())
42 }
43}