mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
object_name: extend ObjectName
This commit is contained in:
parent
4364598449
commit
fa2b155f7d
@ -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()
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user