From fa2b155f7d4ab445ee846298c5876342f6d1d866 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 9 Oct 2018 19:32:22 +0200 Subject: [PATCH] object_name: extend ObjectName --- rust-bindings/rust/libostree/src/object_name.rs | 17 +++++++++++++---- rust-bindings/rust/libostree/src/repo.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rust-bindings/rust/libostree/src/object_name.rs b/rust-bindings/rust/libostree/src/object_name.rs index 05246631..bec63eb8 100644 --- a/rust-bindings/rust/libostree/src/object_name.rs +++ b/rust-bindings/rust/libostree/src/object_name.rs @@ -1,15 +1,14 @@ use ffi; -use functions::object_name_deserialize; +use functions::{object_name_deserialize, object_name_serialize, object_to_string}; use glib; -use glib_ffi; use glib::translate::*; +use glib_ffi; use ObjectType; use std::fmt::Display; use std::fmt::Error; use std::fmt::Formatter; use std::hash::Hash; use std::hash::Hasher; -use functions::object_to_string; fn hash_object_name(v: &glib::Variant) -> u32 { unsafe { ffi::ostree_hash_object_name(v.to_glib_none().0 as glib_ffi::gconstpointer) } @@ -23,7 +22,7 @@ pub struct ObjectName { } impl ObjectName { - pub fn new(variant: glib::Variant) -> ObjectName { + pub fn new_from_variant(variant: glib::Variant) -> ObjectName { let deserialize = object_name_deserialize(&variant); ObjectName { variant, @@ -32,6 +31,16 @@ impl ObjectName { } } + pub fn new>(checksum: S, object_type: ObjectType) -> ObjectName { + let checksum = checksum.into(); + let variant = object_name_serialize(checksum.as_str(), object_type).unwrap(); + ObjectName { + variant, + checksum, + object_type, + } + } + pub fn checksum(&self) -> &str { self.checksum.as_ref() } diff --git a/rust-bindings/rust/libostree/src/repo.rs b/rust-bindings/rust/libostree/src/repo.rs index d46861ef..1fec31a4 100644 --- a/rust-bindings/rust/libostree/src/repo.rs +++ b/rust-bindings/rust/libostree/src/repo.rs @@ -14,7 +14,7 @@ use ObjectName; unsafe extern "C" fn read_variant_table(_key: glib_ffi::gpointer, value: glib_ffi::gpointer, hash_set: glib_ffi::gpointer) { let value: glib::Variant = from_glib_none(value as *const glib_ffi::GVariant); let set: &mut HashSet = &mut *(hash_set as *mut HashSet); - set.insert(ObjectName::new(value)); + set.insert(ObjectName::new_from_variant(value)); }