From 81ea92566f46f6aa0fde71f317956a2e81b65982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20St=C3=BChn?= Date: Tue, 16 Nov 2021 11:28:38 +0100 Subject: [PATCH] update result type --- rust-bindings/rust/src/repo.rs | 33 ++++++++++++++++------- rust-bindings/rust/tests/functions/mod.rs | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/rust-bindings/rust/src/repo.rs b/rust-bindings/rust/src/repo.rs index 486e087c..f44a6c2d 100644 --- a/rust-bindings/rust/src/repo.rs +++ b/rust-bindings/rust/src/repo.rs @@ -24,28 +24,41 @@ unsafe extern "C" fn read_variant_table( set.insert(ObjectName::new_from_variant(value)); } -unsafe extern "C" fn read_variant_table_from_key( +unsafe extern "C" fn read_variant_object_map( key: glib_sys::gpointer, - _value: glib_sys::gpointer, + value: glib_sys::gpointer, hash_set: glib_sys::gpointer, ) { let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant); - let set: &mut HashSet = &mut *(hash_set as *mut HashSet); - set.insert(ObjectName::new_from_variant(key)); + let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant); + if let Some(insert) = value.get::<(bool, Vec)>() { + let set: &mut HashMap)> = &mut *(hash_set as *mut HashMap)>); + set.insert(ObjectName::new_from_variant(key), insert); + } } -unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable, from_key: bool) -> HashSet { +unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet { let mut set = HashSet::new(); - let read_variant_table_cb = if from_key { read_variant_table_from_key } else { read_variant_table }; glib_sys::g_hash_table_foreach( ptr, - Some(read_variant_table_cb), + Some(read_variant_table), &mut set as *mut HashSet as *mut _, ); glib_sys::g_hash_table_unref(ptr); set } +unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap)> { + let mut set = HashMap::new(); + glib_sys::g_hash_table_foreach( + ptr, + Some(read_variant_object_map), + &mut set as *mut HashMap)> as *mut _, + ); + glib_sys::g_hash_table_unref(ptr); + set +} + /// An open transaction in the repository. /// /// This will automatically invoke [`ostree::Repo::abort_transaction`] when the value is dropped. @@ -127,7 +140,7 @@ impl Repo { &mut error, ); if error.is_null() { - Ok(from_glib_container_variant_set(hashtable, false)) + Ok(from_glib_container_variant_set(hashtable)) } else { Err(from_glib_full(error)) } @@ -164,7 +177,7 @@ impl Repo { &self, flags: OstreeRepoListObjectsFlags, cancellable: Option<&P>, - ) -> Result, Error> { + ) -> Result)>, Error> { unsafe { let mut error = ptr::null_mut(); let mut hashtable = ptr::null_mut(); @@ -178,7 +191,7 @@ impl Repo { ); if error.is_null() { - Ok(from_glib_container_variant_set(hashtable, true)) + Ok(from_glib_container_variant_map(hashtable)) } else { Err(from_glib_full(error)) } diff --git a/rust-bindings/rust/tests/functions/mod.rs b/rust-bindings/rust/tests/functions/mod.rs index cf15a3d9..933bc897 100644 --- a/rust-bindings/rust/tests/functions/mod.rs +++ b/rust-bindings/rust/tests/functions/mod.rs @@ -12,7 +12,7 @@ fn list_repo_objects() { let mut commit_cnt = 0; let objects = repo.repo.list_objects( ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE).expect("List Objects"); - for object in objects { + for (object, _items) in objects { match object.object_type() { ObjectType::DirTree => { dirtree_cnt += 1; }, ObjectType::DirMeta => { dirmeta_cnt += 1; },