Function quickjs_runtime::quickjs_utils::sets::clear_q
source · pub fn clear_q(
q_ctx: &QuickJsRealmAdapter,
map: &QuickJsValueAdapter,
) -> Result<(), JsError>
Expand description
remove all entries from a Set
§Example
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use quickjs_runtime::quickjsvalueadapter::QuickJsValueAdapter;
use quickjs_runtime::quickjs_utils::primitives;
use quickjs_runtime::quickjs_utils::sets::{size_q, clear_q, add_q, new_set_q};
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_set: QuickJsValueAdapter = new_set_q(q_ctx).ok().unwrap();
let value = primitives::from_i32(23);
add_q(q_ctx, &my_set, value).ok().unwrap();
clear_q(q_ctx, &my_set).ok().unwrap();
let i_size = size_q(q_ctx, &my_set).ok().unwrap();
assert_eq!(i_size, 0);
});