object_name: extend ObjectName

This commit is contained in:
Felix Krull 2018-10-09 19:32:22 +02:00 committed by Colin Walters
parent 4364598449
commit fa2b155f7d
2 changed files with 14 additions and 5 deletions

View File

@ -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<S: Into<String>>(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()
}

View File

@ -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<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
set.insert(ObjectName::new(value));
set.insert(ObjectName::new_from_variant(value));
}