Switch ObjectName to GString

This commit is contained in:
Felix Krull 2019-05-21 20:29:42 +02:00 committed by Colin Walters
parent 475cd53c43
commit ab3e2c908e
1 changed files with 6 additions and 8 deletions

View File

@ -1,6 +1,7 @@
use functions::{object_name_deserialize, object_name_serialize, object_to_string}; use functions::{object_name_deserialize, object_name_serialize, object_to_string};
use glib; use glib;
use glib::translate::*; use glib::translate::*;
use glib::GString;
use glib_sys; use glib_sys;
use ostree_sys; use ostree_sys;
use std::fmt::Display; use std::fmt::Display;
@ -17,8 +18,7 @@ fn hash_object_name(v: &glib::Variant) -> u32 {
#[derive(Eq, Debug)] #[derive(Eq, Debug)]
pub struct ObjectName { pub struct ObjectName {
variant: glib::Variant, variant: glib::Variant,
// TODO: can I store a GString here? checksum: GString,
checksum: String,
object_type: ObjectType, object_type: ObjectType,
} }
@ -27,12 +27,12 @@ impl ObjectName {
let deserialize = object_name_deserialize(&variant); let deserialize = object_name_deserialize(&variant);
ObjectName { ObjectName {
variant, variant,
checksum: deserialize.0.into(), checksum: deserialize.0,
object_type: deserialize.1, object_type: deserialize.1,
} }
} }
pub fn new<S: Into<String>>(checksum: S, object_type: ObjectType) -> ObjectName { pub fn new<S: Into<GString>>(checksum: S, object_type: ObjectType) -> ObjectName {
let checksum = checksum.into(); let checksum = checksum.into();
let variant = object_name_serialize(checksum.as_str(), object_type).unwrap(); let variant = object_name_serialize(checksum.as_str(), object_type).unwrap();
ObjectName { ObjectName {
@ -43,18 +43,16 @@ impl ObjectName {
} }
pub fn checksum(&self) -> &str { pub fn checksum(&self) -> &str {
self.checksum.as_ref() self.checksum.as_str()
} }
pub fn object_type(&self) -> ObjectType { pub fn object_type(&self) -> ObjectType {
self.object_type self.object_type
} }
// TODO: return GString pub fn name(&self) -> GString {
pub fn name(&self) -> String {
object_to_string(self.checksum(), self.object_type()) object_to_string(self.checksum(), self.object_type())
.expect("type checks should make this safe") .expect("type checks should make this safe")
.into()
} }
} }