Function quickjs_runtime::quickjs_utils::maps::entries_q
source · pub fn entries_q<C: Fn(QuickJsValueAdapter, QuickJsValueAdapter) -> Result<R, JsError>, R>(
q_ctx: &QuickJsRealmAdapter,
map: &QuickJsValueAdapter,
consumer_producer: C,
) -> Result<Vec<R>, JsError>
Expand description
iterate over all entries of a map
§Example
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use quickjs_runtime::quickjs_utils::maps::{new_map_q, set_q, entries_q};
use quickjs_runtime::quickjsvalueadapter::QuickJsValueAdapter;
use quickjs_runtime::quickjs_utils::primitives;
let rt = QuickJsRuntimeBuilder::new().build();
rt.exe_rt_task_in_event_loop(|q_js_rt| {
let q_ctx = q_js_rt.get_main_realm();
let my_map: QuickJsValueAdapter = new_map_q(q_ctx).ok().unwrap();
let key = primitives::from_i32(12);
let value = primitives::from_i32(23);
set_q(q_ctx, &my_map, key, value).ok().unwrap();
let mapped_values = entries_q(q_ctx, &my_map, |key, value| {Ok(123)}).ok().unwrap();
assert_eq!(mapped_values.len(), 1);
});