rs_container_ffi

Crates.iors_container_ffi
lib.rsrs_container_ffi
version2024.12.3
sourcesrc
created_at2024-11-29 09:59:35.345678
updated_at2024-12-03 05:45:47.51834
descriptionWrap Rust Vec, std::collections::{BTreeMap, BTreeSet} for C
homepage
repositoryhttps://github.com/ascpkg/asc/tree/main/rs_container_ffi
max_upload_size
id1465367
size8,159
Capric (capric8416)

documentation

README

Call Rust Vec, std::collections::{BTreeMap, BTreeSet} in C

Docs Crates.io Crates.io

// copy ../c_source_parser_ffi/src/rs_container_ffi/btree_map.h
// full example can be found at ../c_source_parser_ffi

// use rust BTreeMap<String, BTreeSet<String>>
// new BTreeMap<String, BTreeSet<String>>
RustBtreeMapOfStrSet map = rust_btree_set_of_str_new();
// insert key and value to BTreeMap<String, BTreeSet<String>>
rust_btree_set_of_str_insert(map, "key", "value");
// drop BTreeMap<String, BTreeSet<String>>
rust_btree_set_of_str_drop(map);

// use rust BTreeSet<String>
// new BTreeSet<String>
RustBtreeSetOfStr set = rust_btree_set_of_str_new();
// insert foo to BTreeSet<String>
rust_btree_set_of_str_insert(set, "foo");
// insert bar to BTreeSet<String>
rust_btree_set_of_str_insert(set, "bar");
// if foo in BTreeSet<String> return 1 else 0
int is_foo_exists = rust_btree_set_of_str_contains(set, "foo");
// drop BTreeSet<String>
rust_btree_set_of_str_drop(set);

// use rust Vec<String>
// new Vec<String>
RustVecOfStr vec = rust_vec_of_str_new();
// push a to Vec<String>
rust_vec_of_str_push(vec, "a");
// push b to Vec<String>
rust_vec_of_str_push(vec, "b");
// push c to Vec<String>
rust_vec_of_str_push(vec, "c");
// push d to Vec<String>
rust_vec_of_str_push(vec, "d");
// reverse Vec<String>
rust_vec_of_str_reverse(vec);
// join Vec<String>
const char *text = rust_vec_of_str_join("/");  // d/c/b/c
// drop Vec<String>
rust_vec_of_str_drop(vec)
// drop text (do not use c free or c++ delete)
rust_c_str_drop(text);
Commit count: 0

cargo fmt