I can't get first element of the vector because of the error and can't change struct design either. I tried borrowing but struct expects a ExtrudeGeometry.
#[wasm_bindgen]
pub fn toCollection(arr: js_sys::Array, r_type: String) -> JsValue {
let n_arr: Vec<ExtrudeGeometry> = arr.into_serde().unwrap();
if r_type == "GeometryCollection" {
return JsValue::from_serde(&OutputGeometryCollection {
collection: n_arr,
r#type: r_type,
})
.unwrap();
} else {
let ex: ExtrudeGeometry = n_arr[0];
return JsValue::from_serde(&OutputObject {
data: ex,
r#type: r_type,
})
.unwrap();
}
}
error[E0507]: cannot move out of borrowed content
--> src/lib.rs:308:39
|
308 | let ex: ExtrudeGeometry = n_arr[0];
| ^^^^^^^^
| |
| cannot move out of borrowed content
| help: consider borrowing here: `&n_arr[0]`