use std::mem::MaybeUninit; use libc::c_char; #[repr(C)] pub struct HashTable { num_buckets: usize, capacity: usize, occupied: *mut u8, keys: *mut MaybeUninit, vals: *mut MaybeUninit, } type Str = *const c_char; pub type HashMap = HashTable; pub type HashSet = HashTable; impl HashTable { pub fn new() -> Self { HashTable { num_buckets: 0, capacity: 0, occupied: std::ptr::null_mut(), keys: std::ptr::null_mut(), vals: std::ptr::null_mut(), } } } // with alias type MySet = HashTable; #[no_mangle] pub extern "C" fn new_set() -> *mut MySet { Box::into_raw(Box::new(HashSet::new())) } type SetCallback = unsafe extern "C" fn(key: Str); #[no_mangle] pub unsafe extern "C" fn set_for_each(set: *const MySet, callback: SetCallback) { todo!(); } // without alias #[no_mangle] pub extern "C" fn new_map() -> *mut HashTable { Box::into_raw(Box::new(HashMap::new())) } type MapCallback = unsafe extern "C" fn(key: Str, val: u64); #[no_mangle] pub unsafe extern "C" fn map_for_each(map: *const HashTable, callback: MapCallback) { todo!(); }