summaryrefslogtreecommitdiffstats
path: root/tests/rust/const_generics_bool.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:39:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:39:07 +0000
commitaf6b8ed095f88f1df2116cdc7a9d44872cfa6074 (patch)
tree1f2df671c1f8033d5ed83f056167a0911f8d2a57 /tests/rust/const_generics_bool.rs
parentInitial commit. (diff)
downloadrust-cbindgen-af6b8ed095f88f1df2116cdc7a9d44872cfa6074.tar.xz
rust-cbindgen-af6b8ed095f88f1df2116cdc7a9d44872cfa6074.zip
Adding upstream version 0.26.0.upstream/0.26.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/rust/const_generics_bool.rs')
-rw-r--r--tests/rust/const_generics_bool.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/rust/const_generics_bool.rs b/tests/rust/const_generics_bool.rs
new file mode 100644
index 0000000..3047b07
--- /dev/null
+++ b/tests/rust/const_generics_bool.rs
@@ -0,0 +1,57 @@
+use std::mem::MaybeUninit;
+
+use libc::c_char;
+
+#[repr(C)]
+pub struct HashTable<K, V, const IS_MAP: bool> {
+ num_buckets: usize,
+ capacity: usize,
+ occupied: *mut u8,
+ keys: *mut MaybeUninit<K>,
+ vals: *mut MaybeUninit<V>,
+}
+
+type Str = *const c_char;
+pub type HashMap<K, V> = HashTable<K, V, true>;
+pub type HashSet<K> = HashTable<K, u8, false>;
+
+impl<K, V, const IS_MAP: bool> HashTable<K, V, IS_MAP>
+{
+ 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<Str, c_char, false>;
+
+#[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<Str, u64, true> {
+ 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<Str, u64, true>, callback: MapCallback) {
+ todo!();
+}