diff options
Diffstat (limited to 'libsecret/src/schema.rs')
-rw-r--r-- | libsecret/src/schema.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libsecret/src/schema.rs b/libsecret/src/schema.rs new file mode 100644 index 0000000..b3252e2 --- /dev/null +++ b/libsecret/src/schema.rs @@ -0,0 +1,37 @@ +use crate::{Schema, SchemaAttributeType, SchemaFlags}; +use glib::translate::*; +use std::collections::HashMap; + +impl Schema { + #[doc(alias = "secret_schema_new")] + #[doc(alias = "secret_schema_newv")] + pub fn new( + name: &str, + flags: SchemaFlags, + attribute_names_and_types: HashMap<&str, SchemaAttributeType>, + ) -> Self { + unsafe { + let hash_table = glib::ffi::g_hash_table_new_full( + Some(glib::ffi::g_str_hash), + Some(glib::ffi::g_str_equal), + Some(glib::ffi::g_free), + None, + ); + + for (name, type_) in attribute_names_and_types { + let key_ptr: *mut libc::c_char = name.to_glib_full(); + glib::ffi::g_hash_table_insert( + hash_table, + key_ptr as *mut _, + type_.into_glib() as *mut _, + ); + } + + from_glib_full(ffi::secret_schema_newv( + name.to_glib_none().0, + flags.into_glib(), + hash_table, + )) + } + } +} |